Yesterday I scrubbed my previous version of ImageMagick and reinstalled, so that I could use it with Perl 5.6.1 (on Win 2000 Pro). The installation itself went fine, and so did the PPM install Perl::Magick. However, the problem now arises that the two don't appear to speak to each other too well.
I have a little script that simply reads a JPG file and rotates through 90°. The Read() function reports Warning 330: no magic configuration file found (magic.mgk)
. There are several installation guides and FAQs online regarding various Win32 quirks, and having tried them all I still get the error. Just to satisfy my own curiosity, I tried one of the demo scripts, which creates a GIF image, and low and behold it works. I can only assume my error is in relation to the JPG image.
The sad thing is, in my search for a cure I've trawlled the users and developers lists and came across several people with the same or similar problems. Oddly not one of them ever got an answer. I can only assume from that, that either it must be a bug and no-one has figured out a solution, or those that do know a solution can't be bothered to respond. Either way it's a bit disappointing.
I've now given up the ghost and in barely 5mins have rewritten the code to use GD. It works like a charm :)
Re:Script...
barbie on 2004-02-12T18:03:28
This was my simple test script for GD. Ultimately it'll be included in a CGI upload facility I wanted to use, but it gives an idea of what I was after:
#!/usr/bin/perl -w use strict; use GD; my $start = 'D_00a.jpg'; my $image = 'D_00b.jpg'; my $thumb = 'D_00b.png'; my $rotate = 90; # read in current image my $i = GD::Image->newFromJpeg($start) ; print("read image error: [$start]\n") unless $i; return 1 unless $i; # rotate clockwise by $angle degrees my $p = $i->copyRotate90() if($rotate == 90); my $p = $i->copyRotate180() if($rotate == 180); my $p = $i->copyRotate270() if($rotate == 270); writeimage($image,$p->jpeg); my ($w,$h); my ($width,$height) = $p->getBounds(); if($width > $height) { $w = 100; $h = ($height * 100) / $width; } else { $h = 100; $w = ($width * 100) / $height; } my $r = GD::Image->new($w,$h); $r->copyResized($p,0,0,0,0,$w,$h,$width,$height); writeimage($thumb,$r->png); sub writeimage { my ($file,$data) = @_; open DISPLAY, ">$file" || die; binmode DISPLAY; print DISPLAY $data; close DISPLAY; }
Re:Script...
barbie on 2004-02-12T18:06:27
Ignore that last one, I've just discovered that the submit and preview buttons for comments are in a different order to that of journal entries. Bugger!Here's the real script:
#!/usr/bin/perl -w
use strict;
use GD;
my $start = 'D_00a.jpg';
my $image = 'D_00b.jpg';
my $thumb = 'D_00b.png';
my $rotate = 90;
# read in current image
my $i = GD::Image->newFromJpeg($start);
print("read image error: [$start]\n") unless $i;
return 1 unless $i;
# rotate clockwise by $angle degrees
my $p = $i->copyRotate90() if($rotate == 90);
my $p = $i->copyRotate180() if($rotate == 180);
my $p = $i->copyRotate270() if($rotate == 270);
writeimage($image,$p->jpeg);
my ($w,$h);
my ($width,$height) = $p->getBounds();
if($width > $height) {
$w = 100;
$h = ($height * 100) / $width;
} else {
$h = 100;
$w = ($width * 100) / $height;
}
my $r = GD::Image->new($w,$h);
$r->copyResized($p,0,0,0,0,$w,$h,$width,$height);
writeimage($thumb,$r->png);
sub writeimage {
my ($file,$data) = @_;
open DISPLAY, ">$file" || die;
binmode DISPLAY;
print DISPLAY $data;
close DISPLAY;
}
Sorry, just got a bit upset. Good call using GD, if you just want to rotate however use jpegtran which does lossless rotation of jpegs.
Re:Image magick shit
barbie on 2004-02-12T18:19:26
Hmmm. I take it you're not a fan then;p Thanks for the tip about jpegtran, although I was also after thumbnailing to PNG too. I have a particular image upload feature within my pet project that needs updating. I wanted to have something that will work on Windows and Linux, so it seems GD is the winner.
Re:Configuration
barbie on 2004-02-13T11:08:28
Yep, did all that. Also put DLLs in directories everywhere, change the MAGICK_HOME and PATH environment variables, and rebooted (several times) all to no avail. The fact that many people have posted to the imagemagick lists and had no response, doesn't bode well that there is a simple solution:(