Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi there Monks!

I have this sub routine in my code I am using to resize an image once it gets uploaded from a web page/desktop and mobile versions. When I use the desktop version of the site the resizing works, but when an iphone is used to upload the picture the resizing gets ignored and the pictures gets uploaded on its original size. Can someone take a look and help me find what I am doing wrong somewhere cause I cant see it any more.
Here is the code:
sub img_resizing { my (%args) = @_; my $file_name = $args{ file_name } || ''; my $img_location = $args{ img_location } || ''; my $info = image_info("$img_location/$file_name"); my $extension = $info->{file_ext}; #warn Dumper $info; my $oImageMagick = Image::Magick->new; $oImageMagick->Read("$img_location/$file_name"); my $img_width = $oImageMagick->Get('columns'); my $img_height = $oImageMagick->Get('rows'); my $longest = $img_width >= $img_height ? $img_width : $img_height; my $ratio_main = 640 / $longest; $oImageMagick->Resize( width => $img_width * $ratio_main, height => $ +img_height * $ratio_main ); $oImageMagick->Write("$img_location/$file_name"); my $ratio_thumb = 384 / $longest; $oImageMagick->Resize( width => $img_width * $ratio_thumb, height => +$img_height * $ratio_thumb ); $oImageMagick->Write("$img_location/thumbs/$file_name"); } # End Sub img_resizing
Thanks for looking!

Replies are listed 'Best First'.
Re: Image Resizing Help!
by zentara (Cardinal) on Mar 03, 2014 at 17:26 UTC
    I suggest you put some debugging info into to the resizes, and see where it fails. Here is a simple script that shows how to see if the resize fails. It's a peculiar way of doing it, but it works that way for IM.

    Also, see the undef@$image line, which clears out the ImageMagick object's buffers, when run thru loops.

    #!/usr/bin/perl use warnings; use strict; use Image::Magick; use File::Basename; my $image = Image::Magick->new; umask 0022; my @pics= <pics/*.jpg pics/*.gif pics/*.png>; my @exts = qw(.jpg .gif .png); foreach my $pic (@pics){ my ($basename,$path,$suffix) = fileparse($pic,@exts); my $ok; $ok = $image->Read($pic) and warn ($ok); rename ($pic, "$pic.bak") or warn $!; my $resize = "$basename.jpg"; $image->Scale(geometry => '500x500'); $ok = $image->Write("pics/$resize") and warn ($ok); undef @$image; #needed if $image is created outside loop print "$pic ->resize to pics/$resize\n"; }

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
Re: Image Resizing Help!
by zentara (Cardinal) on Mar 03, 2014 at 16:47 UTC
    When I use the desktop version of the site the resizing works, but when an iphone is used to upload the picture the resizing gets ignored and the pictures gets uploaded on its original size.

    I'm guessing maybe the iphone uploads a file with the wrong permissions. Check the ownership and permissions of a succesfull resize and an unsucessfull one.


    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
      I cheeked for that already, not a permission issue.