Python Forum
PIL doesn't seem to paste full size image.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PIL doesn't seem to paste full size image.
#1
I have a folder full of images that I crop to a certain size (100x100 in this case) then I average the colour of the images.

Now for a bit of logic (this is where I might have gone wrong):
If I have an image of which the size is 567,376 and I make the pixels '100 times bigger' - I am actually replacing each pixel with one of the images that I cropped previously, which is technically scaling each pixel 100 times bigger - that in turn would make the image 100 times bigger.
See, if the image is 567 pixels wide, and each one is scaled by 100, it should become 56,700 pixels wide right? Well, it does. And that would mean each pixel position - [0,0], [0,1], [0,2], [0,3] - would be 100 times larger - [0,0], [0,100], [0,200] ,[0,300] At each of these new values, if I pasted a 100x100 image, after enough images it should fill up the new image entirely (after 567 images exactly - 567*100=56700)
However, for some reason, each image I paste seems to be much smaller than it should be.

Let me use the exact image I am using now - it is 768x432, meaning with images pixels 'scaled by 100' it would become 76800x43200, and each pixel is now an entire image. But this is the output I actually get:
[Image: J6bvFJ4.png]
It seems like each image is so much smaller - but according to my logic, there should be no empty space because the images should fill up the whole 'canvas'. Why is going on? Why are the pasted images so small?

Cropping code:
width, height = img.size   #get dimensions
crop_size = 100
if(crop_size > width or crop_size > height): #if image is too small to be cropped
     img.close() #just close it
left = (width - crop_size)/2 #crop from centre out
top = (height - crop_size)/2
right = (width + crop_size)/2
bottom = (height + crop_size)/2
try: #if the image was closed, it cant perform operations so the error will need to be caught
     img = img.crop((left, top, right, bottom))
Pasting code:
to_make = Image.open(options['to_create']) #open the image user wants to recreate
img = Image.new('RGB', (to_make.width*100, to_make.height*100), color = (0,0,0)) #create the new image 
for x in range(0,to_make.width):
    for y in range(0,to_make.height):
         pix_col = to_make.getpixel((x, y)) #get the pixel color
         closest = find_closest(pix_col, rgb) #find the closest matching image to the color of the pixel on the image
         a = Image.open(links[rgb.index(closest)]) #gets the path to the image using the rgb colour
         img.paste(a, (x*to_make.width, y*to_make.height))#pastes image at 100,100 rather than 1,1 otherwise there will be overlap
Reply


Messages In This Thread
PIL doesn't seem to paste full size image. - by DreamingInsanity - Nov-20-2019, 05:08 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  What script to paste folders thenewcoder 1 686 Nov-29-2023, 09:40 AM
Last Post: Pedroski55
  howto get size of a ctk image? janeik 2 901 Oct-03-2023, 03:49 AM
Last Post: janeik
  Please help me [copy and paste file from src to dst] midomarc 2 1,046 Nov-24-2022, 10:13 PM
Last Post: midomarc
  ImageTk Paste KDog 14 7,012 Jun-27-2021, 11:07 AM
Last Post: KDog
  Cut and Paste Oshadha 3 2,465 Jan-20-2021, 04:27 PM
Last Post: spaceraiders
  size of set vs size of dict zweb 0 2,163 Oct-11-2019, 01:32 AM
Last Post: zweb
  copy paste file and re-name it asheru93 1 2,397 May-24-2019, 10:43 AM
Last Post: heiner55
  Locating Grids in full page image KolGuy80 0 1,800 Mar-20-2019, 09:47 AM
Last Post: KolGuy80
  Is there a way to detect the text font, size and color from an image in python? Maia07 2 8,709 Aug-23-2018, 01:16 PM
Last Post: Maia07
  CSV file created is huge in size. How to reduce the size? pramoddsrb 0 10,514 Apr-26-2018, 12:38 AM
Last Post: pramoddsrb

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020