Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7704303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:39:15+00:00 2026-05-31T23:39:15+00:00

what I need: – there are two images: a background (large) and a proifile

  • 0

what I need:
– there are two images: a background (large) and a proifile pic (smaller)
– on background there is an oblique box, where I want to merge the profile pic

Code:

# open the profile pic
im = PIL.Image.open(pic)
# resize it to dim of oblique box
im = im.resize((picX, picY))

# this is the degree of oblique box
degree = 13.67

# open the background
bg = PIL.Image.open(bgsrc)
bgosize = bg.size
bginfo = bg.info


# first, I rotate the background to be paralell with profile pic
bg = bg.rotate(-degree, resample = PIL.Image.BILINEAR, expand = True)

# paste the profile pic to background
bg.paste(im, (px1, py1, px2, py2))

# rotate back to original orientation
bg = bg.rotate(degree, resample = PIL.Image.BILINEAR, expand = False)


# crop the rotated image, because it's greater than original size,
# after first rotate - coords are stored
bg.crop(bgx1, bgy1, bgx2, bgy2)

PIL.ImageFile.MAXBLOCK = bg.size[0] * bg.size[1]
bg.save(dst, quality = 250, optimize = True, **bginfo)

After this transform the result image is nubbly a litlebit…

How can I get a good qualtiy image?

Thanks:

a.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T23:39:16+00:00Added an answer on May 31, 2026 at 11:39 pm

    Hint 1: Use Image.BICUBIC instead of Image.BILINEAR. Unfortunately rotate does not accept Image.ANTIALIAS which would provide an even better result.

    Hint 2: Instead of rotating the background and rotating it back later, rotate the image you want to paste.

    Hint 3: Create an image in 'L' 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 paste.


    I haven’t tested this code but it should work. One question though, what is quality = 250 supposed to accomplish? The JPEG options for example only accept values from 1 to 95.

    # 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) 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need some help about with Memcache. I have created a class and want to
Need to insert selected text on the page into textarea. There must be some
Need a small hand here im trying to combine two functions to create a
Need for two dimensional array of objects that could be something like: myContainer<myObject*> *a
Need to convert byte arrays of images and videos back to its origin. I
Need some help on a script I am doing... what I want to accomplish
Need a function that takes a character as a parameter and returns true if
Need a way to allow sorting except for last item with in a list.
Need to an expression that returns only things with an I followed by either
Need to locate the following pattern: The letter I followed by a space then

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.