Re: image manipulation (scaling)
Ingo Weiss [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hi all, I need have my CGI scale images on the server, and I was wondering whether there is a standard perl module that can do that (and possibly other image manipulation tasks). I am looking for one that: - is easy to understand and use - is likely to be already installed on the server or so well known that my hosting provider is likely to agree to install it for me. If by scaling you mean making thumbnails, I once did this simple CGI program that lets the user upload a jpeg file, uses Image::GD::Thumbnail to resize the image, then sends it back to the user: #!/usr/bin/perl use warnings; use strict; use CGI::Carp qw(fatalsToBrowser warningsToBrowser); use CGI; my $q = CGI-new(); use GD; use Image::GD::Thumbnail; if ( $q-param ) { my $fh = $q-upload('theImage'); # Load your source image my $srcImage = GD::Image-newFromJpeg( $fh ); # Create the thumbnail from it, where the biggest side is 50 px my($thumb,$x,$y) = Image::GD::Thumbnail::create($srcImage, $q-param('theSize')); print $q-header(-type = 'image/jpeg'); binmode( STDOUT ); print $thumb-jpeg; } else { print $q-header(-type = 'text/html'); print $q-start_html( -title = 'jp(e)g to thumbnail converter' ); print $q-h1( 'jp(e)g to thumbnail converter' ); print $q-br( { width = '75%' } ); print $q-div( 'jp(e)g to thumbnail converter' ); print $q-div( 'nbsp;' ); print $q-div( 'Enter A jp(e)g File Name: ' ); print $q-start_multipart_form(); print $q-div( 'Size in pixels you wish the longest side to be: ', $q-textfield( -name = 'theSize', -size = 3, -default = '100', -override = 1, ) ); print $q-div( 'nbsp;' ); print $q-div( $q-filefield('theImage', '', 50) ); print $q-div( 'nbsp;' ); print $q-table( $q-Tr( $q-td( $q-submit ), $q-td( $q-reset ) ) ); print $q-endform; print $q-end_html; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: call a cgi-script from a HTML-form
On Mar 23, 2005, at 5:37 AM, Thomas Bätzler wrote: Grüezi, Krause Susanne [EMAIL PROTECTED] asked: I try to call a Perl-script from a HTML-form (method get). The result, I am getting, is wrong. Instead of executing the script, the webserver is asking me, where I wont to save (per ftp) the Perl-script. What I am doing wrong ? You're asking in the wrong place ;-) I would disagree with that because Krause's message is kind of vague... Calling a perl script from a web browser seems to be a Beginners CGI issue to me, or at least a place to start. This is a web server configuration issue, not a Perl problem. Maybe. Maybe this'll help you: http://httpd.apache.org/docs/howto/cgi.html Can't hurt ;) Krause, you should send a bit more detail. A link to the script and form would help. Kindest Regards, -- Bill Stephenson -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
removing dupes from fetchrow_array()?
Following is the code used in my CGI script. my $query = $dbh - prepare(SELECT * FROM invoices WHERE ID = '$ID'); $query - execute(); while (my @row = $query - fetchrow_array()){ print $row[1] - $row[2] - $row[3]br; } What If I want to remove dupes from @row? like if $row[2] is similar in multiple records, only one entry should be showed, the duplicates should not appear in the print. I am aware of grep, but unable to implement it here in While loop. @row = grep {++$count{$_} 2} @row; I am also aware that Unique keys can be added within mySQL database, but that's un-do-able due to some reasons. I want to remove dupes within the script. Any ideas?
RE: removing dupes from fetchrow_array()?
Sara wrote: Following is the code used in my CGI script. my $query = $dbh - prepare(SELECT * FROM invoices WHERE ID = '$ID'); $query - execute(); while (my @row = $query - fetchrow_array()){ print $row[1] - $row[2] - $row[3]br; } What If I want to remove dupes from @row? like if $row[2] is similar in multiple records, only one entry should be showed, the duplicates should not appear in the print. Like Chris said, typically you want to use SELECT DISTINT or GROUP BY in your query. The rule of thumb is to avoid sending unecessary data from the server to the client. But the general Perl construct I would use to filter dups is something like: my %found; while (...more data...) { $key = ...some expression... next if $found{$key}++; ...process the data for the first occurence... } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: removing dupes from fetchrow_array()?
On 24 Mar, Sara wrote: What If I want to remove dupes from @row? like if $row[2] is similar in multiple records, only one entry should be showed, the duplicates should not appear in the print. Any ideas? #! /usr/bin/perl use strict; use warnings; { local $ = \n; my (@dupes, %have); @dupes = qw(hello hello goodbye goodbye); for (my $i = $#dupes; $i = 0; $i--) { splice(@dupes, $i, 1) if $have{$dupes[$i]}; $have{$dupes[$i]} = 1; }; print @dupes\n; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response