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.
Pythonista Upload Photos from Library
-
@DavinE console.quicklook needs a path, not a pil
filename = 'test.PNG' console.quicklook(filename)
-
@DavinE this works
pil = asset.get_image(original=False) #pil.show() #print(filename) filename = 'test.PNG' console.quicklook(filename) filename = '%s%s' % (console.input_alert('Rename File', 'Message: rename File', hide_cancel_button=False), '.PNG') pil.save(os.path.join(os.path.dirname(sys.argv[0]), filename), quality=95)
-
@cvp said:
@DavinE this works
pil = asset.get_image(original=False) #pil.show() #print(filename) filename = 'test.PNG' console.quicklook(filename) filename = '%s%s' % (console.input_alert('Rename File', 'Message: rename File', hide_cancel_button=False), '.PNG') pil.save(os.path.join(os.path.dirname(sys.argv[0]), filename), quality=95)
No this works not because
console.quicklook(filename)
did not existspil.save
is called later...
i think what i want to do this don't works.. -
-
-
@DavinE thus, all is ok?
-
@DavinE said:
No this works not because console.quicklook(filename) did not exists pil.save is called later...
i think what i want to do this don't works..You are right, sorry. But you can always rename your file after saving it as local.
If you only need to upload the file and to not keep a local copy, usealways the same temp name for local save, thus the quicklook will work.get asset
pil.save as local tempname
quicklook tempname
ask name
Upload to name
remove tempname local -
@cvp said:
@DavinE said:
No this works not because console.quicklook(filename) did not exists pil.save is called later...
i think what i want to do this don't works..You are right, sorry. But you can always rename your file after saving it as local.
If you only need to upload the file and to not keep a local copy, usealways the same temp name for local save, thus the quicklook will work.yes, i got the same idea ;)
here's the code:
assets = photos.pick_asset(title='Pick some assets', multi=True) print(f'assets: {assets}') for asset in assets: pil = asset.get_image(original=False) pil.save(os.path.join(os.path.dirname(sys.argv[0]), 'Images', filename), quality=95) for image in os.listdir(os.path.join(os.path.dirname(sys.argv[0]), 'Images')): console.quicklook((os.path.join(os.path.dirname(sys.argv[0]), 'Images', image))) filename = '%s%s' % (console.input_alert('Rename File', 'Message: rename File', hide_cancel_button=False), '.PNG') # Upload......
Thanks for your help @cvp
-
@DavinE I have edited my post just before reading your last one
-
@cvp the post above yours or which one ?
-
If you want to ftp upload the picked photos, I think you get the asset a binary data and to upload it without passing via a local copy.
Of course, if you want to show the photo without a local file, you can't use quicklook but an ImageView could be sufficient to show the image.... -
-
I don't have any FTP server accessible just now, but you can test this
#pil.save(os.path.join(os.path.dirname(sys.argv[0]), filename), quality=95) temp = io.BytesIO() pil.save(temp, format='JPEG', quality=95) temp.seek(0) #session.storbinary('STOR xxxxx.jpg' , temp)
The pil.save needs a format because, without file name, file type would be unknown
-
Please, if you try this one, please let me know if it is ok
import console import os, sys import photos import io import ui assets = photos.pick_asset(title='Pick some assets', multi=True) for asset in assets: pil = asset.get_image(original=False) iv = ui.ImageView() iv.image = asset.get_ui_image() iv.present('fullscreen') #pil.save(os.path.join(os.path.dirname(sys.argv[0]), filename), quality=95) temp = io.BytesIO() pil.save(temp, format='JPEG', quality=95) temp.seek(0) filename = '%s%s' % (console.input_alert('Rename File', 'Message: rename File', hide_cancel_button=False), '.PNG') #session.storbinary('STOR '+filename , temp)
-
@cvp said:
Please, if you try this one, please let me know if it is ok
import console import os, sys import photos import io import ui assets = photos.pick_asset(title='Pick some assets', multi=True) for asset in assets: pil = asset.get_image(original=False) iv = ui.ImageView() iv.image = asset.get_ui_image() iv.present('fullscreen') #pil.save(os.path.join(os.path.dirname(sys.argv[0]), filename), quality=95) temp = io.BytesIO() pil.save(temp, format='JPEG', quality=95) temp.seek(0) filename = '%s%s' % (console.input_alert('Rename File', 'Message: rename File', hide_cancel_button=False), '.PNG') #session.storbinary('STOR '+filename , temp)
this looks nice.
i try it. -
@cvp said:
Please, if you try this one, please let me know if it is ok
import console import os, sys import photos import io import ui assets = photos.pick_asset(title='Pick some assets', multi=True) for asset in assets: pil = asset.get_image(original=False) iv = ui.ImageView() iv.image = asset.get_ui_image() iv.present('fullscreen') #pil.save(os.path.join(os.path.dirname(sys.argv[0]), filename), quality=95) temp = io.BytesIO() pil.save(temp, format='JPEG', quality=95) temp.seek(0) filename = '%s%s' % (console.input_alert('Rename File', 'Message: rename File', hide_cancel_button=False), '.PNG') #session.storbinary('STOR '+filename , temp)
This works very well @cvp!
i do not need to remove any files ?goes this example also with the (german: Dateien App) Files App to select any file on my Documents ?
-
-
@DavinE said:
i do not need to remove any files ?
No because you did not create any file, you work in memory
-
@DavinE said:
goes this example also with the (german: Dateien App) Files App to select any file on my Documents ?
It should also be ok, but you would have to select a file and read it as binary file
-