Exemplo n.º 1
0
 def dummy_image(self, width, height):
     d = self._get_dummy_image_data(width, height)
     im = Image(Geometry(width, height), Color(*d['canvas_color']))
     im.strokeColor(Color(*d['line_color']))
     im.strokeWidth(1)
     for line in d['lines']:
         im.draw(DrawableLine(*line))
     im.fillColor(Color())
     im.draw(DrawableRectangle(*d['rectangle']))
     return im
Exemplo n.º 2
0
 def getpixels_test_template(self, use_const):
     img = Image(Geometry(300, 200), Color('transparent'))
     getPixelsMethod = img.getConstPixels if use_const else img.getPixels
     pixels = getPixelsMethod(40, 50, 10, 10)
     self.assertEqual(10 * 10, len(pixels))
     with self.assertRaises(IndexError):
         pixels[2000]
     colorMax = Color.scaleDoubleToQuantum(1.0)
     self.assertEqual(0, pixels[0].red)
     self.assertEqual(0, pixels[0].blue)
     self.assertEqual(0, pixels[0].green)
     self.assertEqual(colorMax, pixels[0].opacity)
     return pixels
Exemplo n.º 3
0
 def test_image_resize(self):
     im = Image(Geometry(300, 200), Color('transparent'))
     g = Geometry(150, 100)
     ft = FilterTypes.BlackmanFilter
     blur = 0.5
     im.resize(g, ft, blur)
     im.resize(g, ft)
     im.resize(g)
Exemplo n.º 4
0
    def test_image_setpixels(self):
        img = Image(Geometry(300, 200), Color('transparent'))
        pixels = img.setPixels(40, 50, 5, 5)
        for pixel in pixels:
            pixel.red = 50
        img.syncPixels()

        for pixel in img.getPixels(40, 50, 5, 5):
            self.assertEqual(50, pixel.red)
Exemplo n.º 5
0
 def getpixels_test_template(self, use_const):
     img = Image(Geometry(300, 200), Color('transparent'))
     getPixelsMethod = img.getConstPixels if use_const else img.getPixels
     pixels = getPixelsMethod(40, 50, 10, 10)
     self.assertEqual(10 * 10, len(pixels))
     with self.assertRaises(IndexError):
         pixels[2000]
     colorMax = Color.scaleDoubleToQuantum(1.0)
     self.assertEqual(0, pixels[0].red)
     self.assertEqual(0, pixels[0].blue)
     self.assertEqual(0, pixels[0].green)
     self.assertEqual(colorMax, pixels[0].opacity)
     return pixels
Exemplo n.º 6
0
 def test_color_histogram(self):
     redColor = Color('red')
     im = Image(Geometry(30, 20), redColor)
     histogram = im.colorHistogram()
     self.assertEqual(1, len(histogram))
     # test in, __getitem__
     self.assertIn(redColor, histogram)
     self.assertEqual(30 * 20, histogram[redColor])
     # iteration example
     for packet in histogram:
         color, count = packet.key(), packet.data()
         self.assertEqual(redColor, color)
         self.assertEqual(30 * 20, count)
Exemplo n.º 7
0
 def gen_image(self, size, color_value):
     color = Color(str(color_value))
     if not color.isValid():
         raise ValueError("Color %s is not valid." % color_value)
     return Image(Geometry(size[0], size[1]), color)
Exemplo n.º 8
0
from pgmagick import Image, ImageList, Geometry, Color

imgs = ImageList()
for color in ('red', 'blue', 'green', 'black', 'yellow'):
    imgs.append(Image(Geometry(200, 200), Color(color)))
imgs.animationDelayImages(100)
imgs.scaleImages(Geometry(100, 100))
print len(imgs)
imgs.writeImages('output.gif')

imgs = ImageList()
imgs.readImages('output.gif')
for img in imgs:
    print img
Exemplo n.º 9
0
 def test_stroke_linejoin(self):
     im = Image(Geometry(300, 200), Color('transparent'))
     im.strokeLineJoin(LineJoin.MiterJoin)
     im.strokeLineJoin(LineJoin.RoundJoin)
     im.strokeLineJoin(LineJoin.BevelJoin)
Exemplo n.º 10
0
 def test_size_and_color_init(self):
     im = Image(Geometry(300, 200), Color('transparent'))
     size = im.size()
     self.assertEqual(300, size.width())
     self.assertEqual(200, size.height())
Exemplo n.º 11
0
    def drawTaskPie(self,
                    imgPie,
                    dicTaskTree,
                    globalTimespan=-1,
                    parentTimespan=-1,
                    radiusDelta=10,
                    radiusInner=0,
                    angleStart=0,
                    angleEnd=360):
        if globalTimespan == -1:
            globalTimespan = 0
            for strBranchName in dicTaskTree:
                globalTimespan += dicTaskTree[strBranchName]["time"]

        if parentTimespan == -1:
            parentTimespan = 0
            for strBranchName in dicTaskTree:
                parentTimespan += dicTaskTree[strBranchName]["time"]

        if parentTimespan > 0:
            nSegments = len(dicTaskTree)

            radiusOuter = radiusInner + radiusDelta

            nCenterX = imgPie.columns() / 2
            nCenterY = imgPie.rows() / 2

            nStartXOuter = nCenterX - radiusOuter
            nStartYOuter = nCenterY - radiusOuter
            nEndXOuter = nCenterX + radiusOuter
            nEndYOuter = nCenterY + radiusOuter

            nStartXInner = nCenterX - radiusInner
            nStartYInner = nCenterY - radiusInner
            nEndXInner = nCenterX + radiusInner
            nEndYInner = nCenterY + radiusInner

            dAngleOffset = 0

            for strBranchName in dicTaskTree:
                dAngleWidth = float(
                    dicTaskTree[strBranchName]["time"]) / float(
                        parentTimespan) * (angleEnd - angleStart)

                if dAngleWidth > 0:
                    dStartingAngle = angleStart + dAngleOffset
                    dEndingAngle = dStartingAngle + dAngleWidth
                    dAngleOffset += dAngleWidth

                    if "children" in dicTaskTree[strBranchName]:
                        if len(dicTaskTree[strBranchName]["children"]) > 0:
                            self.drawTaskPie(
                                imgPie, dicTaskTree[strBranchName]["children"],
                                globalTimespan,
                                dicTaskTree[strBranchName]["time"],
                                radiusDelta, radiusOuter, dStartingAngle,
                                dEndingAngle)

                    dTimeSpanDegree = float(dicTaskTree[strBranchName]
                                            ["time"]) / float(globalTimespan)
                    imgPie.strokeColor(
                        Color(int(255 * dTimeSpanDegree), 0,
                              int(255 * (1.0 - dTimeSpanDegree))))

                    lstDrawables = DrawableList()
                    lstDrawables.append(
                        DrawableLine(
                            nCenterX + radiusInner *
                            math.cos(math.radians(dStartingAngle)),
                            nCenterY + radiusInner *
                            math.sin(math.radians(dStartingAngle)),
                            nCenterX + radiusOuter *
                            math.cos(math.radians(dStartingAngle)),
                            nCenterY + radiusOuter *
                            math.sin(math.radians(dStartingAngle))))
                    lstDrawables.append(
                        DrawableArc(nStartXOuter, nStartYOuter, nEndXOuter,
                                    nEndYOuter, dStartingAngle, dEndingAngle))
                    lstDrawables.append(
                        DrawableLine(
                            nCenterX +
                            radiusInner * math.cos(math.radians(dEndingAngle)),
                            nCenterY +
                            radiusInner * math.sin(math.radians(dEndingAngle)),
                            nCenterX +
                            radiusOuter * math.cos(math.radians(dEndingAngle)),
                            nCenterY + radiusOuter *
                            math.sin(math.radians(dEndingAngle))))
                    lstDrawables.append(
                        DrawableArc(nStartXInner, nStartYInner, nEndXInner,
                                    nEndYInner, dStartingAngle, dEndingAngle))

                    imgPie.draw(lstDrawables)
Exemplo n.º 12
0
from pgmagick import Image, Geometry, Color, Coordinate, CoordinateList, \
                     DrawableBezier

im = Image(Geometry(300, 200), Color("white"))
cdl = CoordinateList()
cdl.append(Coordinate(20, 20))
cdl.append(Coordinate(100, 50))
cdl.append(Coordinate(50, 100))
cdl.append(Coordinate(160, 160))
db = DrawableBezier(cdl)
im.draw(db)
im.display()
Exemplo n.º 13
0
 def test_image_thumbnail(self):
     im = Image(Geometry(300, 200), Color('transparent'))
     g = Geometry(150, 100)
     im.thumbnail(g)
Exemplo n.º 14
0
 def test_extent(self):
     im = Image(Geometry(300, 200), Color('transparent'))
     g = Geometry(10, 10)
     im.extent(g)
Exemplo n.º 15
0
from pgmagick import Image, Geometry, Color, TypeMetric, \
                     DrawableText, DrawableList, DrawableGravity, GravityType

im = Image(Geometry(600, 600), Color("transparent"))

im.fontPointsize(30)
im.fillColor(Color("#f010f0"))
im.strokeColor(Color("transparent"))
im.font("Vera.ttf")
dl = DrawableList()

dl.append(DrawableGravity(GravityType.CenterGravity))
dl.append(DrawableText(0, 0, "center"))

tm = TypeMetric()
im.fontTypeMetrics("northn", tm)
font_height = tm.textHeight()
dl.append(DrawableGravity(GravityType.NorthGravity))
dl.append(DrawableText(0, font_height / 2., "north"))

dl.append(DrawableGravity(GravityType.WestGravity))
dl.append(DrawableText(0, 0, "west"))

dl.append(DrawableGravity(GravityType.EastGravity))
dl.append(DrawableText(0, 0, "east"))
dl.append(DrawableText(0, 20, "east-long"))

dl.append(DrawableGravity(GravityType.SouthGravity))
dl.append(DrawableText(0, 0, "south"))

dl.append(DrawableGravity(GravityType.NorthWestGravity))
Exemplo n.º 16
0
#!/usr/bin/python

import sys
from pgmagick import Image, Geometry, Color

if __name__ == "__main__":
    print sys.argv[1]
    im = Image(Geometry(200, 200), Color(sys.argv[1]))
    im.display()
Exemplo n.º 17
0
def export_area(x1, y1, z1, x2, y2, z2, chunks, assets, data):

    if x1 > x2:
        x1, x2 = x2, x1
    if y1 > y2:
        y1, y2 = y2, y1
    if x1 > x2:
        z1, z2 = z2, z1

    cache = {}

    unknow = Image(Geometry(16, 16), "fuchsia")
    hardcoded = {
        'minecraft:air': Color('white'),
        'minecraft:cave_air': Color('black'),
        'minecraft:water':
        Color('blue'),  # TODO use 'block/water_still' with #0080ff tint
        'minecraft:lava': 'block/lava_still',
    }
    for x in hardcoded:
        if isinstance(hardcoded[x], Color):
            hardcoded[x] = Image(Geometry(16, 16), hardcoded[x])
        else:
            hardcoded[x] = Image("%s/textures/%s.png" %
                                 (assets.directory, hardcoded[x]))
            hardcoded[x].crop(Geometry(16, 16))

    for y in range(y2 - y1):
        img = Image(Geometry(16 * (x2 - x1), 16 * (z2 - z1)), 'transparent')
        for z in range(z2 - z1):
            for x in range(x2 - x1):
                try:
                    i = None
                    sid = chunks.get_block_at(x + x1, y + y1, z + z1)
                    if sid in cache:
                        i = cache[sid]
                    else:
                        bloc = data.blocks_states[sid]
                        if bloc in hardcoded:
                            i = hardcoded[bloc]
                        else:
                            prop = data.blocks_properties[sid]
                            variant = assets.get_block_variant(bloc, prop)

                            if 'model' in variant:
                                faces = assets.get_faces_textures(
                                    assets.get_model(variant['model']))
                                if 'up' in faces:
                                    up = faces['up']
                                    i = Image(
                                        "%s/textures/%s.png" %
                                        (assets.directory, up['texture']))
                                    if "uv" in up:
                                        pass  # TODO
                                    i.crop(Geometry(16, 16))
                                    if "tintindex" in up:
                                        tint = '#80ff00'
                                        ti = Image(Geometry(16, 16), tint)
                                        i.composite(
                                            ti, 0, 0, CompositeOperator.
                                            MultiplyCompositeOp)
                        if not i:
                            i = unknow
                        cache[sid] = i

                    img.composite(i, x * 16, z * 16,
                                  CompositeOperator.OverCompositeOp)
                except Exception:
                    continue

        img.write("/tmp/slice_%d.png" % (y))
Exemplo n.º 18
0
image_path = sys.argv[1]
tile_size = int(sys.argv[2])

# Make sure the file actually exists
if not os.path.exists(image_path):
    print >> sys.stderr, "Could not find file!"
    sys.exit(1)

# Get properties of image
image = Image(image_path)
image_width = image.size().width()
image_height = image.size().height()
image_name = image.fileName()

# If the image has the correct size, just exit
if image_width == tile_size and image_height == tile_size:
    sys.exit(0)

# A new image with the correct size is needed, create it
geometry = Geometry(tile_size, tile_size)
color = Color("black")
new_image = Image(geometry, color)
# Copy original image to position 0,0 of new image
new_image.composite(image, 0, 0, co.OverCompositeOp)
# Override original image
new_image.write(image_name)

print >> sys.stdout, "Corrected " + image_name + " from " + str(image_width) + "x" + str(image_height) + " to " + str(tile_size) + "x" + str(tile_size)

Exemplo n.º 19
0
 def gen_image(self, size, color_value):
     color = Color(str(color_value))
     if not color.isValid():
         raise ValueError('Color %s is not valid.' % color_value)
     return Image(Geometry(size[0], size[1]), color)
Exemplo n.º 20
0
from pgmagick import Image, Geometry, Color, \
                     DrawableCircle, DrawableText

im = Image(Geometry(300, 300), Color("yellow"))

circle = DrawableCircle(100.0, 100.0, 20.0, 20.0)
im.draw(circle)

im.fontPointsize(65)
im.font("/var/lib/defoma/x-ttcidfont-conf.d/dirs/TrueType/UnBatang.ttf")
text = DrawableText(30, 250, "hello gm")
im.draw(text)
im.write('circle-text.png')
Exemplo n.º 21
0
 def gen_image(self, size, color):
     if Color(str(color)).isValid():
         img = Image(Geometry(size[0], size[1]), Color(str(color)))
     else:
         raise ValueError
     return img
Exemplo n.º 22
0
 def test_haldClut(self):
     img = Image()
     if hasattr(img, "haldClut"):
         clutimg = Image(Geometry(512, 512), Color('transparent'))
         img.haldClut(clutimg)