Hello I'm having problems opening a image file in web2py. I don't know if I'm making just a simple mistake or that it'd more than that. I thought I was doing it right looking at examples from the web and on this site. Heres my code in the model:
db.define_table('image',
Field('picture', 'upload'))
I think the error means that there is a picture in the database but it can't retrieve that image and open it or I be completely wrong please if anyone can spread some light on the solution i will be very thankful
The parameter passed to Image.open, db.image.picture, is a Field object and not the value that was filled into the form. You probably want:
pic = Image.open(os.path.join(request.folder,'uploads',form.vars.picture))
Edit: Updated to use full path to the picture file. However, as pointed out by Anthony in comments below, this will not work with a blob field that was used to store the image in the original question (before it was edited as discussed in comments below). The use of retrieve as described here will provide the file data.
Related
I am working on a project for my company which tries to read scanned pdfs and classify them depending on their contents.
After doing some research online, the easiest way to solve this seems to be by using a Python Library called pytesseract.
My question is: Is this library safe to use with images containing confidential customer data? Do the images/the extracted text get saved in some server?
I found this link which suggests that it is. But I am lacking understandment of what exactly happens 'behind the scenes' everytime I read an image with the module.
Thanks in advance for any help!
I am using Spyder to edit python code. I plotted a figure like following on my screen:
As you can see I have zoom-in on my menu by playing which I can magnify a ROI like following:
Now I need to send this figure to another person who'd like to view this figure interactively, say do zoom-in/zoom-out as well.So my question is, is there anyway to send this figure in certain format the other person can play with such that me without sending my entire python code?
I tried to the save icon on the menu bar, but I did not see a format that can do what I want. I am new to python, please advice. Thank you.
PS: I think in MATLAB you can do that by saving the figure in certain format, so that as long as the other person has MATLAB installed, he/she does not need the data to see the figure interactively
You need to use the pickle module.
MATLAB saves the figure in a .fig format. This is really just a .mat MATLAB data file with a different extension so MATLAB knows it stores image data. If you change the extension to .mat, you can open it is a refular MATLAB data file and see that it just contains variables storing image information.
The equivalent thing to do in matplotlib is to use the pickle.dump function to save the matplotlib figure object to a file. Someone else can then just load the figure from the file and show it. Although the other person may need to have the same matplotlib version installed.
A better option would be to use something like bokeh to save an interactive HTML plot.
I believe its too late for an answer whereas I think it will help others.
In python, if an interactive figure is plotted in plotly. Then it can be exported as a .html.
For reference please follow official documentation Interactive HTML Export in Python
.
I hope it helps.
Ok, I,ve built my first API example using Django. I had this CSV file that I inserted into my database; then I creates my basic API system. Now I can output a JSON with 3 fields: title, image, description (as they were in the CSV). Perfect.
Now my question is pretty generic but conceptually relevant:
The image field is populated with urls but some of them are not correct. I mean not all of them are pointing to jpg, png or any other image file. I want my api system to output an error when accessing a resource that contains a bad url in the image field.
How can I handle this (and eventual other wrong fields)?
Thank you in advance!
Without seeing how you're using the images, it's hard to say how to handle non-existing files. If you want to throw an exception before the image is used, you can check to see if it exists, and throw one if it doesn't like so:
import os
path_to_file = 'my_image.jpg'
if not (os.path.exists(path_to_file) and os.path.isfile(path_to_file)):
# This needs to be OSError (I think) before Python 3.3 (I think)
raise FileExistsError('The file {} does not exist.'.format(path_to_file))
# do stuff with file if it exists
If you make your question more specific I can make this answer more specific.
Hi Everyone Ive hit a road block in sql. Its the dreaded storing images in sql database. Apparently the solution to this is to store image in a file system. Does anyone know any book or video tutorial that teaches this I cant seem to find any in the web. Im using My Sql and Python to learn how to work with images. I cant find any examples in the web.
Store the image as a file, and store the path of the file in the database.
The fact that the file is an image is irrelevant. If you want a more specific answer, you will need to ask a more specific question. Also, please edit your title so that it corresponds to the question.
ive looked through the current related questions but have not managed to find anything similar to my needs.
Im in the process of creating a affiliate store using zencart - now one of the issues is that zencart is not designed for redirects and affiliate stores but it can be done. I will be changing the store so it acts like a showcase store showing prices.
There is a mod called easy populate which allows me to upload datafeeds. This is all well and good however my affiliate link will not be in each product. I can do it manually after uploading the data feed and going to each product and then adding it as an image with a redirect link - However when there are over 500 items its going to be a long repetitive and time consuming job.
I have been told that I can add the links to the data feed before uploading it to zencart and this should be done using python. Ive been reading about python for several days now and feel im looking for the wrong things. I was wondering if someone could please advise the simplest way for me to get this done.
I hope the question makes sense
thanks
abs
You could craft a python script using csv module like this:
>>> import csv
>>> cartWriter = csv.writer(open('yourcart.csv', 'wb'))
>>> cartWriter.writerow(['Product', 'yourinfo', 'yourlink'])
You need to know how link should be formatted hoping that it could be composed using the other parameters present on csv file.
First, use the CSV module as systempuntoout told you, secondly, you will want to change your header to:
mimetype='text/csv'
Content-Disposition = 'attachment; filename=name_of_your_file.csv'
The way to do it depends very much of your website implementation. In pure Python you would probably do that with an HttpResponse object. In django, as well, but there are some shortcuts.
You can find a video demonstrating how to create CSV files with Python on showmedo. It's not free however.
Now, to provide a link to download the CSV, this depends of your Website. What is the technology behinds it : pure Python, Django, Pylons, Tubogear ?
If you can't answer the question, you should ask your boss a training about your infrastructure before trying to make change to it.