CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate:
Restricting user image by file size and dimensions



Jan 21, 2000, 7:21 PM

Post #1 of 3 (6298 views)
Restricting user image by file size and dimensions Can't Post

I have a message board and I am working on a chat script -- both of which I want to give the user the option to post an image (text field which they enter in a URL).

Not a problem .. that works find and dandy alright. However, I wish to restrict the image by a max file size (50k) and max set of dimensions (WxH).

I've looked through my texts (Camel, Llama and Ram) and only seen something that remotely resembled what I want (File::stat) .. but I believe that is only able to function on local files, no?

Any ideas how to get the file size and width/height of a user's image into variables? If I can get that .. I'd be set.


Jan 21, 2000, 8:40 PM

Post #2 of 3 (6298 views)
Re: Restricting user image by file size and dimensions [In reply to] Can't Post

The only way I know of to do this is to use LWP or Sockets and get the image. Then use Image::Size to get the dimensions.
This will majorly slow things down though. I have made a similar script and gave up on doing what you are trying to do. You may want to just make a special code the user enters for the size of the image and limit that.
(image="http://somedomain/someimage.gif" width=20 height=40)
Then if they do not specify a height and width just set a default one. Also limit the size they can specify. This will not limit the actual bytes of the image but it is better than nothing.

Good Luck


Feb 1, 2000, 6:32 PM

Post #3 of 3 (6298 views)
Re: Restricting user image by file size and dimensions [In reply to] Can't Post

Hmm .. you know what?

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

<input type="hidden" name="(image)width" value=document.(image).width>
<input type="hidden" name="(image)height" value=document.(image).height>

Where name (image) is split from the URL entered by the user.

eg: would place (image) as anthony, so the name would be anthonyheight and value would be document.anthony.height

(all this by using patterns and so on)

So, if those hidden values exceed my specifications (say 250x300) a hypertext link is portrayed instead of embedding the image.

However, I haven't tested whether the image has to physically post first to set those values for W and H.

And I just realized more than one person could name the pic 'anthony' though with different URLs. So, more than just the image name could be used .. perhaps the entire URL as (image)height.

*just spouting ideas -- no, of course I haven't thought EVERYTHING through yet*

*that is what this place is for, no?*



Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives