Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
How to save image via photos.save_image()?
-
I've tried passing along a URL to an image, which didn't work. I kind if expected that, but do i have to create a temporary image file locally to pass it along? Do I have to use PIL?
-
You have to use PIL to load or create an image first, then you can pass that image object to the
save_image
function in thephotos
module.You cannot open an image URL directly with PIL, but it doesn't require a lot of code to download an image into a memory buffer that can then be passed to PIL. Here's an example:
import Image import photos from urllib import urlopen from io import BytesIO print "Downloading image..." url = "http://omz-software.com/pythonista/docs/_static/pythonista_icon.png" img = Image.open(BytesIO(urlopen(url).read())) photos.save_image(img) print "Image saved to camera roll."
-
Great, thanks.
-
hi there, quick searching on Google brings me here.and Im working on image saving ,Is the codes above written in .Net? If yes ,Plz give me more detail guide,thx in adv.as a beginner in image programming ,I just can't figure out which open source code is best suiting me, like<a href="http://www.rasteredge.com/how-to/csharp-imaging/imaging-saving-printing/"> image save </a> sample codes found by Google as well as your codes.Any suggestion is appreciated.
-
@nesca This has absolutely nothing to do with .NET. For information about how to save images in .NET, you might want to search stackoverflow.com (be sure to include .NET in your search), but I'm afraid, we can't really help you here.
-
When saving a photo from an image URL, does it have to be a PNG?
I've been testing it with a few urls and I keep getting 'IOError: cannot identify image file' for JPGs. Works fine for PNGs.
Thanks!
-
Should be fine with .jpg
e.g. (if the URL is in the clipboard)
from photos import save_image from Image import open as open_image from cStringIO import StringIO as string_as_file from urllib import urlopen from clipboard import get as get_clip save_image( open_image( string_as_file( urlopen( get_clip() ).read() ) ) ) print 'Saved'