I am currently trying to deploy a python(2.7) application on the GAE, but I seem to have run into a wall doing so.
In the application I need to apply some transformations on an image's data which I have retrieved in the form of an array of bytes. I proceeded as pointed out by the OP of this question. Everything seems to go fine, until I wish to retrieve back the image's data from the PIL.Image object. The code is:
def transform_image(im_data,ratio):
im = Image.open(BytesIO(im_data))
w,h = im.size
im = im.crop((0,0,w,h-20))
new_b_io = BytesIO()
im.save(new_b_io,format='JPEG')
im.close()
return new_b_io.getvalue()
#I write this data to a new '.jpg' file on my GCS bucket.
Looking at my GAE application logs, the exception being raised is:
UnsupportedOperation: fileno
This is an identified bug with the PIL version 1.1.7 (the only PIL version available with GAE), as pointed out here.
Looking everywhere, all I could manage to understand is to use a more latest version of PIL (preferably Pillow), but as one would imagine, our friends at Google haven't made that an option. I could move to the Google's Image Processing API, but I'd appreciate if I could make my way through with PIL.
I'd appreciate if someone could walk me through this dilemma.
Thanks for your time.
Related
For a business process discovery task, I am trying to generate a process model, following pm4py python library. Here's a sample code:
!pip install pm4py
import pm4py
log = pm4py.read_xes('/content/running-example.xes')
process_model, initial_marking, final_marking = pm4py.discover_petri_net_inductive(log)
pm4py.view_petri_net(process_model, initial_marking, final_marking, format="svg")
However, I get output as:
parsing log, completed traces :: 100%
6/6 [00:00<00:00, 121.77it/s]
But no image as is expected from the website: https://pm4py.fit.fraunhofer.de/getting-started-page#discovery
Being relatively new to the world of python, what I learnt from other coders' suggestions here on SO that always read in depth the source code in case of open source libraries.
Here is pm4py visual links:
https://github.com/pm4py/pm4py-core/blob/afee8b0932283b8f8f02dd2b6cc0968a1f1cc723/pm4py/visualization/process_tree/visualizer.py#L69
and specifically for my example:
https://github.com/pm4py/pm4py-core/blob/afee8b0932283b8f8f02dd2b6cc0968a1f1cc723/pm4py/vis.py#L17
But I am not able to figure out how to manipulate it.
Can someone please point out the problem to me and help me generate the views. Also, if anyone has done business process generations before, maybe if you could suggest me any libraries or techniques to analyse event-logs data it would be really helpful.
to visualize the process models mined in PM4Py, make sure that you have graphviz installed on your computer.
see https://pm4py.fit.fraunhofer.de/install for more information on this.
hey guys I am trying to make the django-video-encoding package work with my code, but it doesn't seem to be converting the videos. I have followed exactly as per the documentation. Can someone help with checking the code I have if I missed anything??
This is the link to the package: https://github.com/escaped/django-video-encoding
Can anyone tell me where I went wrong? I couldn't see any tutorials or much info regarding this package but it seems like its the only one there.
I have given the path to ffmpeg like this (am not sure whether its the right way to provide path). this is in settings.
VIDEO_ENCODING_FFMPEG_PATH = "c:\\ffmpeg\\bin\\ffmpeg.exe"
in my signals.py I have this.
#receiver(post_save, sender=VideoPost)
def convert_video(sender, instance, **kwargs):
enqueue(tasks.convert_all_videos, instance._meta.app_label, instance._meta.model_name, instance.pk)
print('Done converting!')
and this prints after I upload a video, but the conversion does not happen.
I tried to recreate but everything seems smooth to me. I didn't point the ffmpeg location though as I set it up in the PATH instead. Try to to set the ffmpeg as global(system) variable instead.
I'm helping a professor working on a satellite image analysis project, we need 800 images stitching together for a square area at 8000x8000 resolution each image from Google Map, it is possible to download them one by one, however I believe there must be a way to write a script for batch processing.
Here I would like to ask how can I implement this using shell or python script, and how could I download images by google maps url ?
Here is an example of the url:
https://maps.google.com.au/maps/myplaces?ll=-33.071009,149.554911&spn=0.027691,0.066047&ctz=-660&t=k&z=15
However I'm not able to analyse the image direct download link from this.
Update:
Actually, I solved this problem, however due to Google's intention, I would not post the way for doing this.
Have you tried the Google static maps API?
You get 25 000 free requests, but you're limited to 640x640, so you'll need to do ~160 requests at a higher zoom level.
I suggest downloading the images as so: Downloading a picture via urllib and python
URL to start with: http://maps.googleapis.com/maps/api/staticmap?center=-33.071009,149.554911&zoom=15&size=640x640&sensor=false&maptype=satellite
It's been long time since I solved the problem, sorry for the delay.
I posted my code to github here, plz star or fork as you like :)
The idea is to use a virtual web browser at a very high resolution to load the google map page, then do the page capture. The defect is there will be google symbol all around on each image, the solution is to apply over sampling on the resolution on each of the image, then use the stiching technique to stick them all together.
I want to check whether the images is downloaded completely. Is there any library to use?
The images I want to verify including various formats such jpeg, png, bmp etc.
The standard go-to library for that kind of thing in Python is the Python Imaging Library (PIL).
I have used Pyhton Pillow module (PIL) and Imagemagick wrapper wand (for psd, xcf formats) in order to detect broken images, the original answer with code snippets is here.
I also implemented this solution in my Python script here on GitHub.
I also verified that damaged files (jpg) frequently are not 'broken' images i.e, a damaged picture file sometimes remains a legit picture file, the original image is lost or altered but you are still able to load it.
I quote the full answer for completeness:
You can use Python Pillow(PIL) module, with most image formats, to check if a file is a valid and intact image file.
In the case you aim at detecting also broken images, #Nadia Alramli correctly suggests the im.verify() method, but this does not detect all the possible image defects, e.g., im.verify does not detect truncated images (that most viewers often load with a greyed area).
Pillow is able to detect these type of defects too, but you have to apply image manipulation or image decode/recode in or to trigger the check. Finally I suggest to use this code:
try:
im = Image.load(filename)
im.verify() #I perform also verify, don't know if he sees other types o defects
im.close() #reload is necessary in my case
im = Image.load(filename)
im.transpose(PIL.Image.FLIP_LEFT_RIGHT)
im.close()
except:
#manage excetions here
In case of image defects this code will raise an exception.
Please consider that im.verify is about 100 times faster than performing the image manipulation (and I think that flip is one of the cheaper transformations).
With this code you are going to verify a set of images at about 10 MBytes/sec (modern 2.5Ghz x86_64 CPU).
For the other formats psd,xcf,.. you can use Imagemagick wrapper Wand, the code is as follows:
im = wand.image.Image(filename=filename)
temp = im.flip;
im.close()
But, from my experiments Wand does not detect truncated images, I think it loads lacking parts as greyed area without prompting.
I red that Imagemagick has an external command identify that could make the job, but I have not found a way to invoke that function programmatically and I have not tested this route.
I suggest to always perform a preliminary check, check the filesize to not be zero (or very small), is a very cheap idea:
statfile = os.stat(filename)
filesize = statfile.st_size
if filesize == 0:
#manage here the 'faulty image' case
You can guess by attempting to load the image into memory (using PIL or somesuch), but it's possible that some images could be loaded ok without being complete - for example an animated GIF might load fine if you have the header and the first frame of the animation, and you won't notice that later frames of the animation were missing.
A more reliable approach would probably be to use some out-of-band communication, like rather than watching a folder and processing new files as soon as they exist, find some way of hooking into the downloader process and getting it to give you a signal when it decides it is ready.
I installed PIL.
I can import PIL (with no error message)
Then I ran the code mentioned here:
Python images display
And I get this error message:
IOError: decoder jpeg not available
I understand this is Library called libjpeg and (?) it should be installed already.
Or is it part of PIL?
Where is it installed if so?
And if not where can I download it?
What I would like to achieve (and seem to run in one problem after the other), would be simply explainable as a Webgallery which I than want to tweak. But first I need Django to get images from the MEDIA_ROOT and display them in the browser when somebody calls a URL. And then I need one button (Next).
And if Christmas and Easter will fall on the same day I want to get the timestamp of that button click.
I thought that would be a breeze. But now I am in a storm of libjpeg and PIL an Tkinter and Models and photologue and ImageField() and.
If anybody has done that (I guess any simple Image display on a Blog) I would be very very glad to hear this expierence.
I somehow cant understand the standard way to do this and every time I think I have the solution, there is some library missing or it is slightly not what I was looking for.
Thanks for the time!
I wrote an article on how to get libjpeg, PIL to work on Snow Leopard.
http://appelfreelance.com/2010/06/libjpeg-pil-snow-leopard-python2-6-_jpeg_resync_to_restart/
Hope you might find this handy
Try this: http://rodesia.org/2008/03/14/installing-pil-on-the-mac/