Page 1 of 1

problem with enlarge an image using Sample

Posted: 2006-12-07T14:29:33-07:00
by ycul
Original image size is 4.3M, 2588X1731.
after this perl code: $image->Sample(width=>5800, height=>5800);

The file turns to 22M, 5800X3879.

Is there a problem with an image being smaller than what sample/scale
sets it to?

Problem exists only when the image size has to be increased.

Posted: 2006-12-07T16:35:32-07:00
by magick
Post a URL to your image so we can download it and attempt to reproduce the problem.

Posted: 2006-12-08T08:52:53-07:00
by ycul
I donot have a URL, could you give me an email address so I can send it ?

Posted: 2006-12-08T10:16:38-07:00
by magick
Send a private-message. Just click on the PM button.

Posted: 2006-12-08T11:34:21-07:00
by magick
Your image is PDF and JPEG compressed. We got reasonable results with ImageMagick 6.3.1-0 with this script:

Code: Select all

use Image::Magick;

$image=Image::Magick->new(density=>144);
$image->Read('27_009_01.pdf');
$image->Write(filename=>'image.pdf',compression=>'jpeg',quality=>'90');

Posted: 2006-12-11T11:53:48-07:00
by ycul
My problem is in enlarging the image size.

What I did was to convert PDF to TIFF with Group 4 compression with scaling 'Fit in frame', max width of 5800 px, max height of 5800 px and a distort aspect of 1.

Here are the functions I used:

Code: Select all

my ($width, $height) = (5800, 5800); 

my $image = Image::Magick->new; 

$image->Read($infile); # takes a long time 

my ($w, $h) = $image->Get('width', 'height'); 

my ($newW, $newH); 
if ($w / $width >= $h / $height) { 
$newW = $width; 
$newH = $h * $width / $w; 
} else { 
$newH = $height; 
$newW = $w * $height / $h; 
} 

 $image->Sample(width=>$newW, height=>$newH); 
$image->Quantize( colors=>2, colorspace=>'gray' ); 
 $image->Set(compression=>'Group4'); 
$image->Write($outfile); 
It works well by shrinking images who are bigger than 5800x5800; but when i tried with images smaller than the 5800x5800 frame, it not enlarges the image but also increases the file size unreasonably.

Posted: 2006-12-11T16:41:29-07:00
by magick
We use this script:

Code: Select all

use Image::Magick;

$image=Image::Magick->new();
$x = $image->Read('logo:');
warn "$x" if "$x";
$x = $image->Sample('5800x5000');
warn "$x" if "$x";
$x = $image->Quantize(colors=>2, colorspace=>'gray'); 
warn "$x" if "$x";
$x = $image->Write(filename=>'logo.tif',compression=>'Group4');
warn "$x" if "$x";
and it returns a file that is 613078 bytes long which seems reasonable for a 5800x4350image. We're using ImageMagick 6.3.1-1. Here is the description of the resulting image:
  • tiffinfo logo.tif
    TIFF Directory at offset 0x959b0 (612784)
    Image Width: 5800 Image Length: 4350
    Resolution: 72, 72 (unitless)
    Bits/Sample: 1
    Compression Scheme: CCITT Group 4
    Photometric Interpretation: min-is-white
    FillOrder: msb-to-lsb
    Orientation: row 0 top, col 0 lhs
    Samples/Pixel: 1
    Rows/Strip: 4350
    Planar Configuration: single image plane
    DocumentName: logo.tif
    Software: ImageMagick 6.3.1 12/11/06 Q16 http://www.imagemagick.org

Posted: 2006-12-13T15:44:51-07:00
by ycul
magick wrote: We use this script:

Code: Select all

use Image::Magick;

$image=Image::Magick->new();
$x = $image->Read('logo:');
warn "$x" if "$x";
$x = $image->Sample('5800x5000');
warn "$x" if "$x";
$x = $image->Quantize(colors=>2, colorspace=>'gray'); 
warn "$x" if "$x";
$x = $image->Write(filename=>'logo.tif',compression=>'Group4');
warn "$x" if "$x";
and it returns a file that is 613078 bytes long which seems reasonable for a 5800x4350image. We're using ImageMagick 6.3.1-1. Here is the description of the resulting image:
  • tiffinfo logo.tif
    TIFF Directory at offset 0x959b0 (612784)
    Image Width: 5800 Image Length: 4350
    Resolution: 72, 72 (unitless)
    Bits/Sample: 1
    Compression Scheme: CCITT Group 4
    Photometric Interpretation: min-is-white
    FillOrder: msb-to-lsb
    Orientation: row 0 top, col 0 lhs
    Samples/Pixel: 1
    Rows/Strip: 4350
    Planar Configuration: single image plane
    DocumentName: logo.tif
    Software: ImageMagick 6.3.1 12/11/06 Q16 http://www.imagemagick.org


OK. I ran the above program on my machine and got the resulting image of 50888330 bytes. So the problem is in my version of ImageMagic?

tiffinfo logo.tif
TIFF Directory at offset 0x301f568 (50460008)
Image Width: 5800 Image Length: 4350
Resolution: 72, 72 (unitless)
Bits/Sample: 16
Compression Scheme: None
Photometric Interpretation: palette color (RGB from colormap)
FillOrder: msb-to-lsb
Orientation: row 0 top, col 0 lhs
Samples/Pixel: 1
Rows/Strip: 1
Planar Configuration: single image plane
Color Map: (present)
DocumentName: logo.tif
Software: ImageMagick 6.2.6 03/27/06 Q16 http://www.imagemagick.org

Posted: 2006-12-13T19:46:04-07:00
by magick
Looks like you need to upgrade to the latest release of ImageMagick, 6.3.1-1.

Posted: 2006-12-14T07:28:25-07:00
by ycul
Sample() function seems not working properly for logo file, the output file logo.tif is a black screen no matter what size it is changed to.

I just cannot upgrade to the latest version thinking it will work. There could be may be new issues. Is ImageMagick 6.2.6 reported as having a problem with enlarging image using sample?

For the newest release, is there a binary RPM that will run under CentOS?

Thank you.

Posted: 2007-01-08T12:00:06-07:00
by ycul
I have another version of ImageMagick: 6.1.9 08/25/06 Q8 http://www.imagemagick.org.

This one works fine by enlarging logo file but it still does work for enlarging PDF files.

What can I do??