Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 01 Apr 2002 18:53:19 +0200
From:      Paul Everlund <tdv94ped@cs.umu.se>
To:        freebsd-questions@freebsd.org
Subject:   ImageMagick with Perl - conversion problem
Message-ID:  <3CA8907F.4DF85715@cs.umu.se>

next in thread | raw e-mail | index | archive | help
Hi all!

A question not related to FreeBSD, but as maybe someone on
the list has a solution to my problem here, I'll give it a
try. People here seems to know a lot about various stuff, so
that's why I'm posting it.

Background
----------
I want to convert an image from some format (if it's an by
me allowed format) to JPG, resize it if necessary, put a
border around the image, and finally save the image in JPG-
format. I've written a PERL-script that uses ImageMagick's
Perl-module for this task. (I do not want to use convert.)
It works ok for all images except TIFF.

Error description
-----------------
When converting TIFF to JPG (and even from TIFF to TIFF),
the converted image shows vertical red-green-blue stripes
in the image, all the way from left to right. This happens
even if the image is not resized.

Perl-script
-----------
#!/usr/bin/perl

use Image::Magick;

$image = Image::Magick->new;

$in = $ARGV[0];         # Image infile.
$out = $ARGV[1];        # Image outfile.
$w = $ARGV[2];          # Image width.
$h = $ARGV[3];          # Image height.

# Read the image from disk.
$image->Read($in);

# Check if valid image type.
$type = $image->Get('magick');
if($type ne "TIFF" and $type ne "BMP" and $type ne "JPG"
         and $type ne "GIF" and $type ne "PNG")
{
  print("error");
  exit(1);
}

# Get image width and height.
($x, $y) = $image->Get('width', 'height');

# Calculate the aspect ratio.
$aspectRatio = $y / $x;

# Change x and y size if necessary.
$sizeChanged = 0;
if($x > $w)
  {
    $x = $w;
    $y = $x * $aspectRatio;
    $sizeChanged = 1;
  }
if($y > $h)
  {
    $y = $h;
    $x = $y * $aspectRatio;
    $sizeChanged = 1;
  }

# If the original size was wrong, then resize the image.
if($sizeChanged == 1)
  {
    $image->Resize(width => $x, height => $y,
                   filter => 'Cubic', blur => 1);
  }

# Draw a border.
$image->Border(width => 2, height => 2, fill => '#000000');

# Write the image to disk.
$image->Write($out);

print("ok");
exit(0);

-----------------------

Any effort from anyone, trying to help me, is greatly
appreciated!

Thanks in advance!

Best regards,
Paul

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3CA8907F.4DF85715>