*alexandre* has asked for the wisdom of the Perl Monks concerning the following question:

Hi, While deploying my scripts Under Linux I'cannot use Image::Thumbnail to thumb an image. here is the script
#!/usr/bin/perl use CGI; use Image::Thumbnail; my $imgdir= "/var/www/upload"; my $query = new CGI; uploadImage('test_upload_and_thumb.jpg'); sub uploadImage { my $name = shift || ''; my $file = $query->upload('image'); open(LOCAL, ">$imgdir/$name") or print 'error'; my $file_handle = $query->upload('image'); + binmode LOCAL; while(<$file_handle>) { print LOCAL; } close($file_handle); close(LOCAL); createImageMagickThumb("$name"); } sub createImageMagickThumb { my $filename = shift || ''; my $t = new Image::Thumbnail( size => 55, create => 1, input => '$imgdir/$filename', outputpath => '$imgdir/thumb.$filename', ); print "Content-Type: text/html\n\n"; print "outputpath => '$imgdir/thumb.$filename'"; }
I didn't facing any error the file test_upload_and_thumb.jpg is uploaded but no thumb is created and no error in the server log. Thanks

Replies are listed 'Best First'.
Re: Image::Thumbnail work under windows but not on linux
by Corion (Patriarch) on Aug 13, 2019 at 13:16 UTC

    Is CGI necessary to reproduce the problem? Can you remove the module and CGI functionality while still getting the error? Maybe consider running the CGI script from the command line instead?

    open(LOCAL, ">$imgdir/$name") or print 'error';

    Consider outputting the error text to the web server error log instead:

    my $filename = open(LOCAL, ">$filename") or die "Could't create '$filename': $!";

    Also consider using the approach documented in CGI for file uploads:

    use File::Copy 'copy'; my $filehandle = $q->upload( 'uploaded_file' ); my $tmpfilename = $q->tmpFileName( $filehandle ); cp $tmpfilename => $filename;
      Hi, I Added die directive but still no error, the image file is still uploaded but thumb not created. I checked if GD, Image::Thumbnail was correctly installed but Don't find any error.

        Which directive did you add, and where?

        Maybe consider outputting the progress of your script using warn to the error log.

        As you already have the appropriate input file in /var/www/upload/test_upload_and_thumb.jpg, you can simply call createImageMagickThumb("$name"); in another program from the shell to test it.

Re: Image::Thumbnail work under windows but not on linux
by hippo (Archbishop) on Aug 14, 2019 at 08:19 UTC

    I'd be very interested to hear why you have decided to use neither strict nor warnings nor taint mode.

    sub createImageMagickThumb { my $filename = shift || ''; my $t = new Image::Thumbnail( size => 55, create => 1, input => '$imgdir/$filename', outputpath => '$imgdir/thumb.$filename', ); print "Content-Type: text/html\n\n"; print "outputpath => '$imgdir/thumb.$filename'"; }

    As is plain from the above, your use of single quotes in the arguments to Image::Thumbnail->new means that the paths will not be interpolated. I would go so far as to suggest that this code, as written, isn't doing what you think on windows either.

      I'd be very interested to hear why you have decided to use neither strict nor warnings nor taint mode.
      Because this guy is just another unteachable cargo culter.


      holli

      You can lead your users to water, but alas, you cannot drown them.

      On a side note, the default <code> font makes distinguishing single and double quotes rather difficult here; any advice on something to add to my custom CSS in display settings to make it more readable? I like the reduced type size for code, but the " looks almost exactly like a bold ' (') here.

        As haukex wrote, the monospace font is set in your browser config. However, there is one setting here which may help. In Display Settings, in the Code Listing Settings there is an option "Large Code Font" which, if checked, will increase the font size of the code listings without changing the font face. That might be all you need?

        PM doesn't seem to enforce any font on its <pre> tags, so it should be using whatever is the default fixed-width font in your browser, so you should be able to change it in your browser's settings. If you're on Windows, I like the new "Consolas" font, and on Ubuntu, "Ubuntu Mono" isn't bad.

Re: Image::Thumbnail work under windows but not on linux
by jcb (Parson) on Aug 14, 2019 at 03:29 UTC

    What is the corresponding script that does work on Windows?

    And a style suggestion: change uploadImage to acceptUploadedImage to better describe what it actually does. The image has been uploaded before your script begins to run.