Forum Archive

How to share JPEGs via dialogs.share_image?

halloleooo

I use dialogs.share_image(img) to share an photo from Pythonista to other apps.

The photo is given as a PiL image and it seems to be shared as a PNG which is pretty inefficient for photos.

Any idea how I can share the photo as a JPEG?

cvp

@halloleooo this shares a jpg

import console
console.open_in('a.jpg')
halloleooo

Thanks @cvp.

Does this mean I have save the PIL image first as a JPG to disk and then I can share it?

ccc

https://omz-software.com/pythonista/docs/ios/console.html says that console.open_in() takes a file_path.

cvp

@halloleooo

import console
from PIL import Image
import os
pil = Image.open('test:Lenna')
pil.save('test.jpg', quality=95)
console.open_in('test.jpg')
os.remove('test.jpg')
cvp

@halloleooo said:

Does this mean I have save the PIL image first as a JPG to disk and then I can share it

Yes sir

halloleooo

Thanks for the details. I was hoping to be able to tweak dialogs.share)image to export JPGs, but the detour via a JPG file is ok too.

Thanks again!

cvp

@halloleooo said:

hoping to be able to tweak dialogs.share)image to export JPGs

I don't think it is possible but I can be wrong

cvp

@cvp said:

save the PIL image first as a JPG to disk

Don't forget that on a iDevice, files are also in RAM 🤔

ccc

I woulda said that solid state disk (SDD/flash) != RAM but perhaps someone could correct me.

cvp

@ccc solid state memory = transistors
RAM = read and write memory = transistors too
Agree this not the same, specially in access speed, buT not exactly a disk which is in movement...
Only different words

Anyway, I only wanted to say that they are similar because in solid state material both

halloleooo

@cvp @ccc Funny, funny., but a good point: These days everything is semiconductors...

In regards to the problem at hand: Using the file systems means I have to create a tmpdir first I guess - or where the heck does the stuff get saved when Pythonista executes in a share extension???

cvp

@halloleooo said:

where the heck does the stuff get saved when Pythonista executes in a share extension???

I guess in the same folder as the script.
And no need of temp dir if you remove it just after sharing.

ccc

As usual, Python has nice batteries included...
https://docs.python.org/3/library/tempfile.html#tempfile.NamedTemporaryFile