Loading an image section from a website in python?

Currently I can download the full image from the url using

from PIL import Image, ImageTk
import cStringIO
import urllib

url = http://prestigemgmt.us/wp-content/uploads/2013/03/dog.jpg
self.image = Image.open(cStringIO.StringIO(urllib.urlopen(url).read()))

      

It works fine and gets the whole image from the site. My question is is there a way to get, say, just the right half of the image.

I understand that I can edit the image after uploading it, but speed is an important aspect, so ideally I will only upload what I need.

+3


source to share


1 answer


It cannot be done.

Common image file formats such as PNG and JPEG are encoded in such a way that you cannot load an arbitrary part of an image without loading the complete image.

You need to download the whole picture, decode it and edit it after downloading.



For advanced knowledge, you can always explore PNG and JPEG formats .

If you are in control of the server providing the images, you can write a server-side script that edits the image on the server and then sends the edit over the wire.

+5


source







All Articles