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 7617323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:07:18+00:00 2026-05-31T03:07:18+00:00

So I have a table with image sizes. There are multiple images of different

  • 0

So I have a table with image sizes. There are multiple images of different sizes (66×66, 400×400, etc.). I have one example of image (the original) that always has a size of 600×532, and on this image is a product (a TV, a PC, etc.).

I have to resize this image, which isn’t a problem. But if I do this with proportion I get something like 66×55. If I don’t do this with proportion the image doesn’t look good.

So the background of the original is always white. Is there a way to extend the area of the image and filling the rest with white?
So like this: 600×532 -> 600×600 -> 66×66 etc etc.

It should be like a anti-crop.

EDIT: I found out that if I use crop() from PIL and instead of “minimizing” using a value above the actual image-size it creates my extra area. but it is going to be black.
Any idea how I could fill this area white?

EDIT2: I guess it has something to do with ImageDraw.

EDIT3: After finding out that ImageDraw was the solution, my problem was solved. Please close this.

Here my solution:

import Image, ImageDraw
img1 = Image.open("img.jpg")
img2 = img1.crop((0,0,600,600))
draw = ImageDraw.Draw(img2)
draw.rectangle( (0,532,600,600), fill='white' )
del draw
img2.save("img2.jpg","JPEG", quality=75)

The next thing I will do is to make the extra crop above and under. So the picture stays in the middle.

EDIT4: final solution

img1 = Image.open("img1.jpg")
img2 = img1.crop( (0,-34,600,566) )  
draw = ImageDraw.Draw(img2)
draw.rectangle( (0,0,600,34), fill="white" )
draw.rectangle( (0,566,600,600), fill="white" )
del draw
img2.save("img2.jpg", "JPEG", quality=75)
  • 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-31T03:07:19+00:00Added an answer on May 31, 2026 at 3:07 am

    Supposing we use PIL to process the image

    from PIL import Image
    
    def white_bg_square(img):
        "return a white-background-color image having the img in exact center"
        size = (max(img.size),)*2
        layer = Image.new('RGB', size, (255,255,255))
        layer.paste(img, tuple(map(lambda x:(x[0]-x[1])/2, zip(size, img.size))))
        return layer
    

    You could resize a PIL Image object, img for example

    img.resize((width, height), resample=Image.ANTIALIAS)
    

    Thus in the python shell, it looks like

    >>> from PIL import Image
    >>> img = Image.open('path/to/image')
    >>> square_one = white_bg_square(img)
    >>> square_one.resize((100, 100), Image.ANTIALIAS)
    >>> square_one.save('path/to/result')
    

    There are nice examples inside PIL document and sorl-thumbnail 3.2.5

    • http://effbot.org/imagingbook/image.htm
    • http://pypi.python.org/pypi/sorl-thumbnail/3.2.5
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to have a table header that looks like the image shown
I'm currently having trouble showing images in a table. The images all have different
I have a table in SQL Server 2005. alt text http://www.techpint.com/sites/default/files/images/table.JPG I want to
I have given a table background image using css background-image property. The cells are
I have a table with an image inside: <table style=border: 3px solid rgb(0, 0,
I have a table in SQL Server. This table has an image field and
In my database I have table AnimalDetails containing animalNumber(primary key),name,breed dateofbirth and an image
I have a table which has two text boxes and an image beside it
I have a table with a varbinary(max) column for an image. I have dropped
I have a table in which each of its TD contains image (more precisely,

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.