Page 1 of 1

Creating an Empty File

Posted: 2009-07-20T19:06:32-07:00
by pgn674
I have Ubuntu 9.04. I had ImageMagick 7:6.4.5.4.dfsg1-1ubuntu3.1 installed from the repositories, as well as PerlMagick of the same version. I noticed that when I tried to use SetPixel, it always made the blue component maxed up (as in 1 or 255). I have heard that it's best to have the most recent version of PerlMagick when trying to use SetPixel, so I uninstalled what I had from the repositories and built a new install from this site, version 6.5.4-3 2009-07-20 Q16 OpenMP. The building and installing went fine, and the checks here worked OK.

Now it's developed a different problem. My perl scripts that worked at least half well, though a little blue, with the older version of PerlMagick are now just making empty files. The .png files I'm trying to write come out with 0 bytes. I have below an example script that results in this lack of substance in the resulting file. It runs through just fine with no errors or dieing, all the way to the checkpoint at the end. Might anyone know what's going on?

Code: Select all

#!/usr/bin/perl

use strict;
use warnings;
use strict 'refs';
use Image::Magick;

my $image=Image::Magick->new(size=>'10x10');
$image->ReadImage('xc:white');

my @pixel;
$pixel[0]=.7;
$pixel[1]=.5;
$pixel[2]=0;
$image->SetPixel(channel=>"All",x=>0,y=>0,color=>\@pixel);

my @pixels;
@pixels = $image->GetPixel(x=>0,y=>0);
print "Pixel gotted: ($pixels[0],$pixels[1],$pixels[2])\n";

my $filename = "pixelTest.png";
open(IMAGE, ">$filename") || die "Can't open $filename: $!";
$image->Write(file=>\*IMAGE, filename=>$filename) || die "Couldn't write image using path of :$filename";
close(IMAGE);
print "Check point\n";
exit;

Code: Select all

$ ./pixelTest.pl 
Pixel gotted: (0.699992370489052,0.500007629510948,0)
Check point

Re: Creating an Empty File

Posted: 2009-07-20T19:23:36-07:00
by magick
Unfortunately we cannot reproduce the problem. Your script returns a 229 byte PNG image that is predominately white other than the pixel at (0,0). We're using ImageMagick 6.5.4-3 and Perl v5.10.0.

Re: Creating an Empty File

Posted: 2009-07-21T16:01:07-07:00
by pgn674
I figured it out. I didn't have a PNG developer library installed before I compiled ImageMagick. So, I installed libpng12-dev from the repositories, and re-configured, made, installed, and tested ImageMagick, and now it creates the file OK. Thank you for taking a look at it earlier. Oh, and I have Perl v5.10.0.

I figured out what was wrong by finding that Write returns the number of images written. When I tried to get that number, I got an error message returned instead: "Exception 420: no encode delegate for this image format `pixelTest.png' @ constitute.c/WriteImage/1114". I got a nice hint as to what was going on from here.

And, good news: when I set a black pixel, it really is black, and not blue, so all this upgrading to the newest version was worth it.

For other Ubuntu users that want to use the most recent version of ImageMagick instead of the version from the repositories, be sure to install those image libraries first. Also, you may need to put "export LD_LIBRARY_PATH=/usr/local/lib" in ~/.bashrc and log out and back in before compiling to get around an "error while loading shared libraries: libMagickCore.so.2: cannot open shared object file: No such file or directory" error.

Oh, and one more thing. If I have the "or die" thing with my Write line in my Perl script, it dies with the error "Inappropriate ioctl for device", even though it had just written the PNG file just fine. Taking out the "or die" catch allows the script to keep running, and it completes OK.