Probelem about image size and dimensions

G

gongcheng_g

I got a piece of python script to upload file and it can upload it to
different folders on server depend on the type of file is image or not.
but I also want to restrict the size and dimensions of file if it is a
image file.Could anyone help me out?


Parameter List:id, file, title='',folder

REQUEST=context.REQUEST
content_type=file.headers['Content-Type']
if content_type.find('image')!=-1: #.find() is a method in Python2.0<


destination=context.restrictedTraverse('/cheng/rvdpas/uploadImage/'+folder)
destination.manage_addImage(id, file, title)\


else:

destination=context.restrictedTraverse('/cheng/rvdpas/uploadDocument/'+folder)
destination.manage_addFile(id, file, title)


return 'Finished'
 
D

Diez B. Roggisch

I got a piece of python script to upload file and it can upload it to
different folders on server depend on the type of file is image or not.
but I also want to restrict the size and dimensions of file if it is a
image file.Could anyone help me out?


Use PIL, the python imaging library. Load your image, check its sizes and
proceed accordingly.

Diez
 
C

ChengGong

Thank you for your reply. I have been learning python only 2 weeks.
According what u said. I tried to import Image but there 's an error
on the server.
here is the message
Error Type: ImportError
Error Value: import of "Image" is unauthorized
 
D

Diez B. Roggisch

ChengGong said:
Thank you for your reply. I have been learning python only 2 weeks.
According what u said. I tried to import Image but there 's an error
on the server.
here is the message
Error Type: ImportError
Error Value: import of "Image" is unauthorized

Are you by chance running under ZOPE? Then you'll need a so-called
ExternalMethod for your code to import restricted modules.

Diez
 
C

ChengGong

Diez,

I asked the administrator that they won't allow me to import Image and
PIL in Zope.
I am wondering that how can I get the height and width and the size of
the image in this situation?
Can I just use <dtml>to get Image's addtributs?

Cheng
 
D

Diez B. Roggisch

ChengGong said:
Diez,

I asked the administrator that they won't allow me to import Image and
PIL in Zope.
I am wondering that how can I get the height and width and the size of
the image in this situation?
Can I just use <dtml>to get Image's addtributs?

No. At least not easily. You'd have to write the whole image-header loading
yourself. Which is certainly more than a two-week-old python coder is
capable of.

If I were you I'd pester your sysadmins to allow you to create an external
method - after all it is _their_ job to make you happy as a developer -
IMHO.

Diez
 
C

ChengGong

Hi Diez,

They do not allow me to do what u said above.
so I do not have any idea what is supposed to do.
however i am think that if I can get the id of the image, i have chance
to modify it.
This is what i programed but it is an empty page, I but it in images
folder
<dtml-var standard_html_header>

<h1>File Library</h1>

<table>
<tr>
<th><a href="&dtml-URL0;?sort=name">File</a></th>
<th><a href="&dtml-URL0;?sort=date">Last Modified</a></th>
</tr>

<dtml-if expr="_.has_key('sort') and sort=='date'">
<dtml-in expr="objectValues(['Image'])"
sort="bobobase_modification_time" reverse>
<tr>
<td><a href="&dtml-absolute_url;"><dtml-var
title_or_id></a></td>
<td><dtml-var bobobase_modification_time fmt="aCommon"><td>
</tr>
</dtml-in>
<dtml-else>
<dtml-in expr="objectValues(['Image'])" sort="id">
<tr>
<td><a href="&dtml-absolute_url;"><dtml-var
title_or_id></a></td>
<td><dtml-var bobobase_modification_time fmt="aCommon"><td>
</tr>
</dtml-in>
</dtml-if>

</table>

<dtml-var standard_html_footer>

is there any mistake?
How ever thank you alot Diez. Your comments and suggestion are helpful.

P.S. i am doing my internship in a commercial company:(, create
external method is not allowed in my situation

Cheng
 
C

ChengGong

Is that because I can not import PIL ? then i can not use codes above
to show all image id?
 
D

dwelch

I got a piece of python script to upload file and it can upload it to
different folders on server depend on the type of file is image or not.
but I also want to restrict the size and dimensions of file if it is a
image file.Could anyone help me out?


Parameter List:id, file, title='',folder

REQUEST=context.REQUEST
content_type=file.headers['Content-Type']
if content_type.find('image')!=-1: #.find() is a method in Python2.0<


destination=context.restrictedTraverse('/cheng/rvdpas/uploadImage/'+folder)
destination.manage_addImage(id, file, title)\


else:

destination=context.restrictedTraverse('/cheng/rvdpas/uploadDocument/'+folder)
destination.manage_addFile(id, file, title)


return 'Finished'

You could try this to get the image dimensions:


http://www.python.org/pypi?:action=...ummary=&description=&keywords=&_pypi_hidden=0

-Don
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top