Gossamer Forum
Home : General : Perl Programming :

Check Image size - How to do ??

Quote Reply
Check Image size - How to do ??
Good morning friends,
I am working (learning) on a file upload script.
And I want to limit the width and height of the images.

Could someone help me with a CGI-code-snipped that does the following:
(Lets say maxheight=250 maxwidth=300)
If the picture exceeds or maxheight or maxwidth
then send to a sub called "&errorsize"
This sub would print a message saying:
"Picture size to big, reduce it or upload another picture"

Regards and Greetings,
Sanuk

Quote Reply
Re: Check Image size - How to do ?? In reply to
Hi Sanuk:

Here is a good starting point:
http://search.cpan.org/...ge-Size-2.93/Size.pm


Dan Cool

LotusLand
Vancouver, BC, Canada
Top Ranked City in World for Quality of Life
Quote Reply
Re: Check Image size - How to do ?? In reply to
Thanks Dan
Seems complicated for me !!!
Do I have to upload this module to my CGI-bin ???
Because I only have a virtual shared wedsite.
Thanks for replying.
Regards,
Sanuk

Quote Reply
Re: Check Image size - How to do ?? In reply to
First check to see if Size.pm is installed in the server where your account is hosted. You can use the following script:

In Reply To:

#!/usr/local/bin/perl
#
#############################################################
# File Name: modules.cgi
# Written by Widgetz, Jerry, Gossamer Threads Scripts User
# Last Modified: November 08,1999
#############################################################

use strict;
use File::Find;
my (@mod, %done, $dir);
find(\&get, grep { -r and -d } @INC);
@mod = grep(!$done{$_}++, @mod);
foreach $dir (sort { length $b <=> length $a } @INC) {
foreach (@mod) { next if s,^\Q$dir,,; }
}
print "Content-type: text/html\n\n";
foreach (@mod) { s,^/(.*)\.pm$,$1,; s,/,::,g; print "$_
\n"; }
print "Done! ($#mod modules!)\n\n";
sub get { /^.*\.pm$/ && /$ARGV[0]/i && push @mod, $File::Find::name; }


* Change the Perl path to your Perl path.
* Save the script as modules.cgi.
* Upload it to your server in an executable folder.
* Change the permissions of the script to 755 (chmod 755 modules.cgi)

If Size.pm is not listed when you execute modules.cgi, then that means that you will need to install the module locally in your account.

If Size.pm is installed, then all you have to use in the file size checking script is:

Code:

use Size;


If it is not installed and you have to install it locally in your account, then use the following codes to reference the module:

Code:

require "/full/path/to/Size.pm";


Then to write the file size check script, use the following references:

perldocs -size
Perl for Dummies
http://www.perl.com

Regards,

Eliot Lee
Quote Reply
Re: Check Image size - How to do ?? In reply to
There's no need in using that script.

From telnet just type:

shell> locate Size.pm

If nothing shows up then it isn't installed Wink

Installs:http://www.wiredon.net/gt/
MODS:http://wiredon.net/gt/download.shtml

Quote Reply
Re: Check Image size - How to do ?? In reply to
A better test is:

/usr/bin/perl -MSize -e 0

and if it produces nothing, then you are ok, if it produces an error, then it's not installed.

That is of course you have shell access in the first place an now how to use it, otherwise use Eliot's suggestion. =)

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Check Image size - How to do ?? In reply to
Paul,

That is fine and dandy on UNIX/Linux servers with shell access...but a Perl script like the one I provided is more universally accessible for webmasters who may be on a Windows NT and do not have SHELL access, and those that may be on a UNIX/LINUX server, but do NOT have SHELL access.

Thus, the solution I provided is more universally applicable and accessible.

Bye.

Regards,

Eliot Lee
Quote Reply
Re: Check Image size - How to do ?? In reply to
Thanks for all Your answers.
I have used Anthrorules script to check my server
It was not installed !!!!!
I now have downloaded size.pm and installed it locally in my CGI-bin.
BUT I am having BIG problems using it.
The explanation inside is very small for CGI Newbies as me.

The Picture that is uploaded thru my script is called "$uploadfile".
I now want to check if the width is bigger than 300 pixels
or if the height is bigger than 400 pixels.
If Bigger then send to "sub errorsize"
which would be a message telling the picture is out of size.
Does someone use size.pm and know the parameters.
Thanks in advance.
Regards,
Sanuk