I'm trying to load this PSD image with Python Imaging Library.
http://www.2shared.com/photo/JjSY7dN-/BG1.html
I'm not very familiar with layered images. Can someone check to see what's the issue? The image appears to be completely transparent. Opening it in my image editor I noticed that the only layer in the image was hidden, I could unhide it to see the colors.
When I load the image with PIL, I get the same issue, but it seems that PIL consolidates the layers into one and I can't do the same as in my image editor. Or maybe there's something I don't know.
PIL provides only very rudimentary hooks into the PSD format. It doesn't support writing or much in the way of manipulation. Your image layer is not shown, so it results in a transparent image. You'll need something more advanced to modify the PSD.
Here's all there is about the PSD format in PIL: http://www.pythonware.com/library/pil/handbook/format-psd.htm
Soon to be available here: http://effbot.org/imagingbook/format-psd.htm
Related
I am creating a program that requires a background image in Python Turtle.
I know how to add the image (bgpic("")) but I need to resize it. I can't use photoshop because I can't then add the file (says that it has no data in the file!).
So how do I resize it through code?
With Pillow you can easily do it :)
here is the doc of the library and the resize function
http://pillow.readthedocs.org/en/3.0.x/reference/Image.html?highlight=resize#PIL.Image.Image.resize
I'm fairly new to PIL and having issue with some image processing. I'm just trying to resize an image to a different resolution using PIL:
resized_hd = image.resize((hd_width, hd_height), Image.ANTIALIAS)
However, the resized picture does not look as good/bright as the original one.
Original (5184*3456) -> http://d31d9cjolqcwln.cloudfront.net/San+Francisco/sutro+baths.jpg
Resized (2048*1366) -> http://d31d9cjolqcwln.cloudfront.net/San+Francisco/HD-sutro+baths.jpg
Any guess ?
I think it's because one of the two images (the original one) has an embedded color profile, which the other one (the resized one) doesn't have. I discovered this by trying to open the original image in gimp. The color profile will cause advanced viewers to make corrections, in theory to fix differences like the ones between paper and screen. When I view the two images in a simple viewer that doesn't know about color profiles, they are really the same brightness. It looks like the PIL library ignores the color profile and doesn't carry it onto the resized image.
I can't help you more precisely than that, though, as I don't know much about color profiles. There might be tools to copy the profile over.
Kuddo to Armin for his suggestion.
Pil allow you to attach an ICC profile to a resized image using the following code:
icc_profile = im1.info.get('icc_profile')
im6 = im1.resize((hd_width, hd_height), Image.ANTIALIAS)
## this one will preserve the colours
im6.save("colorok-"+image,icc_profile=icc_profile)
## this one don't
im6.save("nop-"+image)
Tried looking in the PIL module but couldn't find this covered.
I have an image, and I need to take a cropped piece of the image and move it to a different area within the same image. Simple enough, but I will need to do this for thousands of images, so I will do batch image processing.
PIL seems too basic for this, any other libraries?
Actually, PIL looks like it can do it very well, if you want to copy and paste rectangular areas.
Check the documentation on the crop and paste methods on image, on the documentation here:
http://effbot.org/imagingbook/image.htm
If you need non-rectangular areas, though, you will have to resort to more sophisticated handling, but that does not preclude you from doing it with PIL.
Yes, check OpenCV.
How to crop images with opencv in python
The Python wrapper for the GD library should do what you need:
copyTo(image[, (dx,dy)[, (sx,sy)[, (w,h)]]])
copy from (sx,sy), width sw and height sh to destination image (dx,dy)
I want to load a number of images from harddrive and place them on a larger white background. And I want to do it in Python. I am wondering what is the best way of doing that. I am using a windows machine and I can use any library I want. Any pointer to a webpage or a sample code that can point me to a good direction would be appreciated.
Something like this:
A very popular image processing library for Python is PIL. The official PIL tutorial might be useful, especially the section about "Cutting, Pasting and Merging Images".
PIL isn't enough. Try also with PIL the aggdraw library.
But aggdraw also isn't enough. It works poorly with transparency. I mean 0.5-1 gray pixel around opaque object over the transpparent area.
When resizing images along the lines shown in this question occasionally the resulting image is inverted. About 1% of the images I resize are inverted, the rest is fine. So far I was unable to find out what is different about these images.
See resized example and original image for examples.
Any suggestions on how to track down that problem?
I was finally able to find someone experienced in JPEG and with some additional knowledge was able to find a solution.
JPEG is a very underspecified
Format.
The second image is a valid JPEG but it is in CMYK color space, not in RGB color space.
Design minded tools (read: things from Apple) can process CMYK JPEGs, other stuff (Firefox, IE) can't.
CMYK JPEG is very under specified and the way Adobe Photoshop writes it to disk is borderline to buggy.
Best of it all there is a patch to fix the issue.
Your original image won't display for me; Firefox says
The image “http://images.hudora.de/o/NIRV2MRR3XJGR52JATL6BOVMQMFSV54I01.jpeg”
cannot be displayed, because it contains errors.
This suggests that the problem arises when you attempt to resize a corrupted JPEG, and indeed your resized example shows what looks like JPEG corruption to my eye (Ever cracked open a JPEG image and twiddled a few bits to see what it does to the output? I have, and a few of my abominable creations looked like that). There are a few JPEG repair tools out there, but I've never seriously tried any of them and don't know if they might be able to help you out.