Probelem about image size and dimensions

Discussion in 'Python' started by gongcheng_g@hotmail.com, Mar 23, 2006.

  1. Guest

    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'
    , Mar 23, 2006
    #1
    1. Advertising

  2. wrote:

    > 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
    Diez B. Roggisch, Mar 23, 2006
    #2
    1. Advertising

  3. ChengGong Guest

    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
    ChengGong, Mar 23, 2006
    #3
  4. ChengGong wrote:

    > 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
    Diez B. Roggisch, Mar 23, 2006
    #4
  5. ChengGong Guest

    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
    ChengGong, Mar 23, 2006
    #5
  6. ChengGong wrote:

    > 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
    Diez B. Roggisch, Mar 23, 2006
    #6
  7. ChengGong Guest

    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
    ChengGong, Mar 23, 2006
    #7
  8. ChengGong Guest

    Is that because I can not import PIL ? then i can not use codes above
    to show all image id?
    ChengGong, Mar 23, 2006
    #8
  9. dwelch Guest

    wrote:
    > 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
    dwelch, Mar 23, 2006
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kenny
    Replies:
    1
    Views:
    667
    Travis Murray
    Dec 13, 2004
  2. =?Utf-8?B?Sm9l?=

    how to dynamic assign two dimensions array size

    =?Utf-8?B?Sm9l?=, Mar 15, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    310
    Alexey Smirnov
    Mar 15, 2007
  3. Laphan
    Replies:
    3
    Views:
    324
    Mark Schupp
    Dec 30, 2004
  4. John
    Replies:
    4
    Views:
    103
  5. John
    Replies:
    0
    Views:
    87
Loading...

Share This Page