Probelem about image size and dimensions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • gongcheng_g@hotmail.com

    #1

    Probelem about image size and dimensions

    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=fi le.headers['Content-Type']
    if content_type.fi nd('image')!=-1: #.find() is a method in Python2.0<


    destination=con text.restricted Traverse('/cheng/rvdpas/uploadImage/'+folder)
    destination.man age_addImage(id , file, title)\


    else:

    destination=con text.restricted Traverse('/cheng/rvdpas/uploadDocument/'+folder)
    destination.man age_addFile(id, file, title)


    return 'Finished'

  • Diez B. Roggisch

    #2
    Re: Probelem about image size and dimensions

    gongcheng_g@hot mail.com wrote:
    [color=blue]
    > 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?[/color]


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

    Diez

    Comment

    • ChengGong

      #3
      Re: Probelem about image size and dimensions

      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

      Comment

      • Diez B. Roggisch

        #4
        Re: Probelem about image size and dimensions

        ChengGong wrote:
        [color=blue]
        > 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[/color]

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

        Diez

        Comment

        • ChengGong

          #5
          Re: Probelem about image size and dimensions

          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

          Comment

          • Diez B. Roggisch

            #6
            Re: Probelem about image size and dimensions

            ChengGong wrote:
            [color=blue]
            > 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?[/color]

            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

            Comment

            • ChengGong

              #7
              Re: Probelem about image size and dimensions

              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_h eader>

              <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="objectVal ues(['Image'])"
              sort="bobobase_ modification_ti me" reverse>
              <tr>
              <td><a href="&dtml-absolute_url;"> <dtml-var
              title_or_id></a></td>
              <td><dtml-var bobobase_modifi cation_time fmt="aCommon">< td>
              </tr>
              </dtml-in>
              <dtml-else>
              <dtml-in expr="objectVal ues(['Image'])" sort="id">
              <tr>
              <td><a href="&dtml-absolute_url;"> <dtml-var
              title_or_id></a></td>
              <td><dtml-var bobobase_modifi cation_time fmt="aCommon">< td>
              </tr>
              </dtml-in>
              </dtml-if>

              </table>

              <dtml-var standard_html_f ooter>

              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

              Comment

              • ChengGong

                #8
                Re: Probelem about image size and dimensions

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

                Comment

                • dwelch

                  #9
                  Re: Probelem about image size and dimensions

                  gongcheng_g@hot mail.com wrote:[color=blue]
                  > 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=fi le.headers['Content-Type']
                  > if content_type.fi nd('image')!=-1: #.find() is a method in Python2.0<
                  >
                  >
                  > destination=con text.restricted Traverse('/cheng/rvdpas/uploadImage/'+folder)
                  > destination.man age_addImage(id , file, title)\
                  >
                  >
                  > else:
                  >
                  > destination=con text.restricted Traverse('/cheng/rvdpas/uploadDocument/'+folder)
                  > destination.man age_addFile(id, file, title)
                  >
                  >
                  > return 'Finished'
                  >[/color]

                  You could try this to get the image dimensions:




                  -Don

                  Comment

                  Working...