in reply to Re^3: Image::Thumbnail work under windows but not on linux
in thread Image::Thumbnail work under windows but not on linux

Hi Here the the code snippet I'm been using :
#!/usr/bin/perl use warnings; use strict; use Image::Thumbnail; my $imgdir= "/var/www/upload"; createImageMagickThumb('testFileUploadAndThumb.jpg'); sub createImageMagickThumb { my $filename = shift || ''; print "file name : $filename\n"; print "file directory $imgdir\n"; my $t = new Image::Thumbnail( size => 100, create => 1, input => "$imgdir/$filename", outputpath => "$imgdir/thumb.$filename", ); print "input => $imgdir/$filename\n"; print "outputpath => $imgdir/thumb.$filename\n"; }
and here is the console view
root@vps8279:/usr/lib/cgi-bin# perl thumb.pl file name : testFileUploadAndThumb.jpg file directory /var/www/upload input => /var/www/upload/testFileUploadAndThumb.jpg outputpath => /var/www/upload/thumb.testFileUploadAndThumb.jpg
In my upload directory I still doesn't have a thumb.testFileUploadAndThumb.jpg created

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

    The documentation for Image::Thumbnail shows the following usage:

    use Image::Thumbnail 0.65; # Create a thumbnail from 'test.jpg' as 'test_t.jpg' # using ImageMagick, Imager, GD or Image::Epeg. my $t = new Image::Thumbnail( size => 55, create => 1, input => 'test.jpg', outputpath => 'test_t.jpg', ); # Create four more of ever-larger sizes for (1..4){ $t->{size} = 55+(10*$_); $t->create; }

    I don't see any call to ->create in your code. Did you forget that call?

    Update: Now I see - create => 1 is supposed to automatically create the thumbnail. If you use the automatic way, you won't get access to the error diagnostics, so I would look at the manual way first, to see the potential error messages:

    my $t = new Image::Thumbnail( size => 55, create => 1, input => 'test.jpg', outputpath => 'test_t.jpg', ); $t->create; print "Errors : " . $t->{error, "\n"; print "Warnings:" . $t->{warning}, "\n";

    Upon reading the source code, it seems as the module does not actually set up those fields in most situations.

      Solved by using module Imager within this code
      #!/usr/bin/perl use warnings; use strict; use Image::Thumbnail; my $imgdir= "/var/www/upload"; createImageMagickThumb('testFileUploadAndThumb.jpg'); sub createImageMagickThumb { my $filename = shift || ''; print "file name : $filename\n"; print "file directory $imgdir\n"; my $t = new Image::Thumbnail( module => 'Imager', create => 1, size => 100, input => "$imgdir/$filename", outputpath => "$imgdir/thumb.$filename", ); print "input => $imgdir/$filename\n"; print "outputpath => $imgdir/thumb.$filename\n"; }