Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Hint 1: Use <code>Image.BICUBIC</code> instead of <code>Image.BILINEAR</code>. Unfortunately <code>rotate</code> does not accept <code>Image.ANTIALIAS</code> which would provide an even better result.</p> <p>Hint 2: Instead of rotating the background and rotating it back later, rotate the image you want to paste.</p> <p>Hint 3: Create an image in <code>'L'</code> format that is pure white and the same size as the image you're pasting. Rotate it the same way. Use it as a mask argument to <code>paste</code>. <hr> I haven't tested this code but it should work. One question though, what is <code>quality = 250</code> supposed to accomplish? The <a href="http://www.pythonware.com/library/pil/handbook/format-jpeg.htm" rel="nofollow">JPEG options</a> for example only accept values from 1 to 95.</p> <pre><code># open the profile pic im = PIL.Image.open(pic) # resize it to dim of oblique box im = im.resize((picX, picY), PIL.Image.ANTIALIAS) # this is the degree of oblique box degree = 13.67 # open the background bg = PIL.Image.open(bgsrc) bgosize = bg.size bginfo = bg.info # create a copy of the profile that is all white mask = PIL.Image.new('L', im.size, 0xff) # rotate the profile and the mask im = im.rotate(degree, resample = PIL.Image.BICUBIC, expand = True) mask = mask.rotate(degree, resample = PIL.Image.BICUBIC, expand = True) # paste the profile pic to background bg.paste(im, (px1, py1, px2, py2), mask) PIL.ImageFile.MAXBLOCK = bg.size[0] * bg.size[1] bg.save(dst, quality = 250, optimize = True, **bginfo) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload