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

I've been stumbling along with Imagemagick for some time now and can get most of what I need done, despite what I see as limited help from docs/user groups, etc.. Most of the info available seems to be command line related and of little or (usuall) no help to me. I'd like to know if anyone can tweak the following code to convert the image to 72dpi and save me another month of searching. Any help would be greatly appreciated.
$image_file = Image::Magick -> new(); $result = $image_file -> Read($_[0]); ($mark_width, $mark_height, $mark_size, $mark_fmt) = $image_file -> Pi +ng($_[0]); if ( ($mark_height >= $mark_width) and ( $mark_height > 300) ){ $mark_width = sprintf("%.0f", ( ($mark_width * 300)/$mark_height ) + ) ; $mark_height=300; } $result = $image_file -> Scale(width=>$mark_width, height=> $mark_heig +ht); $result = $image_file -> Write("../new_file/$_[0]");

Replies are listed 'Best First'.
Re: Hard Times With ImageMagick
by hossman (Prior) on Dec 12, 2002 at 00:06 UTC

    I've been stumbling along with Imagemagick for some time now and can get most of what I need done, despite what I see as limited help from docs/user groups, etc.. Most of the info available seems to be command line related and of little or (usuall) no help to me...

    One thing you have to keep in mind with packages like Image::Magick, is that it is a very thin perl shell over a C api ... there aren't a lot of docs on the individual methods, because the C versions are allready heavily documented.

    One great resource is the perl section of the ImageMagick site. You should also search the C++ docs for DPI where you'll find that you want the set the "density" attribute (and then check the perl docs to see how to do that).

Re: Hard Times With ImageMagick
by ThingFish (Beadle) on Dec 12, 2002 at 15:41 UTC
    This should work:

    $image_file->Set(density=>'72x72');

    However, if you are looking at the JPEG file with another program (such as Photoshop) then it is important to know that Photoshop stores density (and other attributes) in an application-specific profile and ignores the standard density setting in the JPEG file header if the profile exists. Hope this helps
Re: Hard Times With ImageMagick
by zentara (Cardinal) on Dec 12, 2002 at 14:37 UTC
    Hi, here is an ImageMagick thumbnail script that works for jpgs. I'm not sure about the 72dpi, but I'm sure that is somewhere in the docs.
    #!/usr/bin/perl use strict; use Image::Magick; my $im = Image::Magick->new; umask 0022; my @names = @ARGV ? @ARGV : grep { -f and -B } <*>; for (@names) { if (/ /) { my $old = $_; tr, ,_,s; $_ .= ".jpg" unless /\.jpg$/; ! -e and rename $old, $_ or next; warn "renaming $old to $_\n"; } next if /\.thumb\.jpg$/; my $thumb = "$_.thumb.jpg"; next if -e $thumb; undef @$im; my $ret; $ret = $im->Read($_) and warn($ret), next; $ret = $im->Scale(geometry => '100x100') and warn($ret), next; $ret = $im->Write($thumb) and warn($ret), next; warn "thumbnail made for $_\n"; }