Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

How to resize picture in windows?

by gube (Parson)
on Aug 05, 2005 at 02:19 UTC ( [id://481063]=perlquestion: print w/replies, xml ) Need Help??

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

Dear Monks,

I want to resize some uploading picture size in my client site. Already, I have done in linux using Image::Magick module. But, in windows i cannot able to install Image::Magick , i can't able to find the exact image::magick.ppd files through ppm also it's not found. Can any one know how to install image::magick module in windows. please let me know.

Thanks in advance.

Replies are listed 'Best First'.
Image::Magick module sample program code and steps for Windows?
by gube (Parson) on Aug 06, 2005 at 01:37 UTC

    Dear monks,

    I have asked the question before How to resize picture in windows?. Each of them answered in very different way many thanks for their ideas. And José Ramón Martínez, ask to reply the code when it works. Yeah, you may download ImageMagick-6.2.3-6-Q16-windows-dll.exe from the path http://www.imagemagick.org/script/binary-releases.php#windows and install it in your windows, while installing there is an option in checkbox Install PerlMagick for ActiveStatePerl check it and install it will automatically install with module in your system. Than, try the below code to resize the image. Congrats, to all. And thanks to astroby to give me a installer link.

    use Image::Magick; my($image, $x); $image = Image::Magick->new; $x = $image->Read('Images.jpg'); warn "$x" if "$x"; $x = $image->Crop(geometry=>'200x50'); warn "$x" if "$x"; $x = $image->Write('x.png'); warn "$x" if "$x";

    Reparented by davido per consideration.

Re: How to resize picture in windows?
by blahblahblah (Priest) on Aug 05, 2005 at 03:11 UTC
    I tried the Image::Magick module a while ago but never got it working. You can use ImageMagick directly though, without the module -- it comes with a bunch of utility programs. I found an old resizing script of mine that uses "mogrify.exe". Here's part of the script:
    $ENV{'PATH'} = "C:\\Program Files\\imageMagick;" . $ENV{'PATH'}; # ... for my $file (@files) { $fileNumber++; my $newFile = "$largeDir\\$basename$fileNumber.JPG"; print "$fileNumber copying $file...\n"; copy("$originalDir\\$file", $newFile); open(INFO, "identify $newFile |"); my $info = <INFO>; close INFO; my ($width, $height) = ($1, $2) if ($info =~ /\s(\d+)x(\d+)\s/); my ($newWidth, $newHeight, $thumbWidth, $thumbHeight); if ($width == 1200 && $height == 1600) { ($newWidth, $newHeight) = (600, 800); ($thumbWidth, $thumbHeight) = (98, 130); } elsif ($width == 1600 && $height == 1200) { ($newWidth, $newHeight) = (800, 600); ($thumbWidth, $thumbHeight) = (130, 98); } else { ($newWidth, $newHeight) = (600, 600); ($thumbWidth, $thumbHeight) = (98, 98); } my $newDimensions = $newWidth . 'x' . $newHeight; my @command = ('mogrify', '-quality', '100', '-geometry', $newDimensions, $newFile); print "mogrifying $newFile...\n"; system(@command);
    (Note: I've only used this code with a version of ImageMagick that I downloaded 4 or 5 years ago.)

    -Joe

Re: How to resize picture in windows?
by astroboy (Chaplain) on Aug 05, 2005 at 03:22 UTC
    Don't install the Image::Magick module on Windows via ppm. Just install the Image Magick application binaries and the installer will ask you if you want to install the Image::Magick module when it detects Perl.
Re: How to resize picture in windows?
by GrandFather (Saint) on Aug 05, 2005 at 02:44 UTC

    There is an "Image-Magick-Thumbnail-Fixed" module if that is of any use:


    Perl is Huffman encoded by design.
Re: How to resize picture in windows?
by BrowserUk (Patriarch) on Aug 05, 2005 at 03:40 UTC

    If you can get GD installed, then something like this will get you started:

    #! perl -slw use strict; use GD; our $X ||= 100; our $Y ||= 100; for my $imgName ( @ARGV ) { my $img1 = GD::Image->new( $imgName ) or warn "$imgName: $!" and n +ext; my $img2 = GD::Image->new( $X, $Y, 1 ); $img2->copyResampled( $img1, 0,0, 0,0, $X,$Y, $img1->getBounds ); ( my $thumbName = $imgName ) =~ s[(\..+$)][.thumb.png]; open OUT, '>:raw', $thumbName or warn "$thumbName: $!" and next; print OUT $img2->png; close OUT; }

    It resizes every image supplied on the command line to the same size (100x100 by default) and outputs them as filename.ext => filename.thumb.png.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.
Re: How to resize picture in windows?
by zentara (Archbishop) on Aug 05, 2005 at 11:09 UTC
    And there are Imager ppms that work on windows. And you can resize like this:
    # Convert image from data in scalar my $img = Imager->new; $img->read(data=>$PixData, type=>'jpeg') or die "Cannot read: ", $img->errstr; my $thumb = $img->scale(scalefactor=>.3); $thumb->write(file=>"$0-t.jpg", type=>'jpeg') or die "Cannot write: ",$img->errstr;
    Instead of 'data=>', you can use 'file=>' to read from a file.

    I'm not really a human, but I play one on earth. flash japh
Re: How to resize picture in windows?
by josera (Beadle) on Aug 05, 2005 at 08:05 UTC
    Hello:
    In this web page:
    http://www.dylanbeattie.net/magick/
    you cand find the binary for image::magick for windows, but it works with the version 5.6 of perl and doesn't work with the version 5.8
    Good luck!.
    If you make that it works, please let me know.
    Thank you
    José Ramón Martínez
        Here is something to complicate it all more (just a bit):

        I once found Graphic::Magick - It was presented as IM's windows stable release. But now, I can't find it again!

        { \ ( ' v ' ) / }
        ( \ _ / ) _ _ _ _ ` ( ) ' _ _ _ _
        ( = ( ^ Y ^ ) = ( _ _ ^ ^ ^ ^
        _ _ _ _ \ _ ( m _ _ _ m ) _ _ _ _ _ _ _ _ _ ) c h i a n o , a l b e r t o
        Wherever I lay my KNOPPIX disk, a new FREE LINUX nation could be established

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://481063]
Approved by polettix
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-04-24 23:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found