Forum Archive

render_text() and image_quad()

saper

The code :

https://gist.github.com/anonymous/dfc5685a2b2a49762660

digit 9 in black - drawn with image()
Digit 9 in red - drawn using image_quad()

I'd like to clip the digit using image_quad() , but it seems to me that the image inserted via image_quad() is larger than its image() equivalent (by factor of ca. 1.5).

What am I doing wrong?

ccc

The URL does not work for me. Is it a private gist or a public one?

saper

I am sorry, it got truncated, should be https://gist.github.com/anonymous/dfc5685a2b2a49762660

Btw if some automatic scaling is involved, this is on a non-retina iPad mini. Running Pythonista 1.5 on iOS 7.1.2.

Screenshot depicting black background, little white rectangle in the middle containing two digits "9", one smaller, black, fitting the rectangle and the other, red, larger, slightly offset towards northeast and overflowing the rectangle.

saper

https://gist.github.com/anonymous/729d5437fc105b18c3a1

With font size 45 the digits start to overlap more, here is with 400:

with font size 400

JonB

Do you have a retina device? i wonder if this is a bug in how retina is handled with double resolution. I solved this by doubling the from_x etc params:

        image_quad(img, pos[0], pos[1],
                    pos[0]+siz.w, pos[1],
                   pos[0], pos[1]+siz.h,
                   pos[0]+siz.w, pos[1]+siz.h, 0.,0.,siz.w*2,0,0,siz.h*2,siz.w*2,siz.h*2
                 )
saper

No, I don't.

I wonder if scene.render_text() really builds the image or just creates a kind of text layer that gets generated later.

I have achieved what I wanted to do with PIL ImageDraw and ImageFont and it works fine, probably because PIL is actually rendering the text here before moving on.

JonB

i think this is an image_quad bug, the optional from parameters are incorrectly scaled, i think by a factor of 2.
for example
image_quad('iob:alert_256',0,0, 256,0,0,256, 256,256,0,0,256,0,0,256,256,256)

produces a clipped image. note, you could also use image with the from parameters if you are just trying to crop. image_quad is for drawing warped quadrilaterals, regular image works fine for rectangles.

        (img, siz) = render_text('9','Helvetica',100)
        rect(pos[0],pos[1],siz[0]-6,siz[1]-40)
        tint(0,0,0)
        image(img, pos[0], pos[1],siz[0]-6,siz[1]-40,3,20,siz[0]-6,siz[1]-40)