Image::Magick: find the last image read 
Author Message
 Image::Magick: find the last image read
Hi!

Do you know how to find the image latest read into an Image::Magick
object?

I need to read several image and make a montage out of them, but before
edit each image in different way without saving it.

Or maybe it is possible to insert an object of single image into an object
of multiple image?

Thank you.

--
                                   S P Arif Sahari Wibowo
  _____  _____  _____  _____

_____/ /      /    / _____/       http://www.*-*-*.com/



Mon, 19 Jul 2004 05:59:58 GMT  
 Image::Magick: find the last image read
On Wed, 30 Jan 2002 15:59:58 -0600,

Quote:
> Hi!

> Do you know how to find the image latest read into an Image::Magick
> object?

An Image::Magick object is just an array reference (as the
documentation explains), so you can just pull out its last element.
Each element in the array in turn is also an Image::Magick object, so
you can call any method on it that you want.

To get the last element from an array, use the index -1:

my $im = Image::Magick->new();
# Do things with the $im object that create images

my $last_im = $im->[-1];

Quote:
> I need to read several image and make a montage out of them, but before
> edit each image in different way without saving it.

That is a different question. To loop over the images:


And, of course you can get at each individual image by referring
directly to its index. Since that image is also an Image::Magick
object, you can invoke any method on it. To rotate the fourth image in
the sequence, and blur the first:

$im->[3]->Rotate($angle);
$im->[0]->Blur($blur_amount);

Quote:
> Or maybe it is possible to insert an object of single image into an object
> of multiple image?

Sorry, I have trouble parsing this question...

Martien
--
                                |
Martien Verbruggen              |
Trading Post Australia Pty Ltd  | values of Beta will give rise to dom!
                                |



Mon, 19 Jul 2004 06:08:30 GMT  
 Image::Magick: find the last image read

Quote:

>An Image::Magick object is just an array reference (as the
>documentation explains), so you can just pull out its last element.
>Each element in the array in turn is also an Image::Magick object, so
>you can call any method on it that you want.

Thank you. The actual structure of the object and how the method treat
them are what I need to know. In this case, that the Image::Magick will
put the latest image as the last element.

I know use Data::Dumper to understand it more.

This bring me another question:

Quote:
>> I need to read several image and make a montage out of them, but before
>> edit each image in different way without saving it.
>That is a different question. To loop over the images:

Oh no, that is related to the question, since the program will have the
information on what to do when it just read the file. That's why it need
to find that last file.

Quote:
>> Or maybe it is possible to insert an object of single image into an object
>> of multiple image?
>Sorry, I have trouble parsing this question...

I mean, read it into an empty Image::Magick object, do the changes, and
then insert the object to another existing Image::Magick object that act
as collector.

It seems that using push will be enough to do that, right?

Thanks.

--
                                   S P Arif Sahari Wibowo
  _____  _____  _____  _____

_____/ /      /    / _____/       http://www.arifsaha.com/



Mon, 19 Jul 2004 06:53:05 GMT  
 Image::Magick: find the last image read
See below.

--
Cheers
Ron Savage

http://savage.net.au/index.html

Quote:
> Hi!

> Do you know how to find the image latest read into an Image::Magick
> object?

The Image::Magick constructor 'new' returns a reference to an array, so you can index into it to process any one image.

You only need to change line 22 [my($dir_name) = '/Scripts/ImageMagick';] to suit your setup.

Tested code:

-----><8-----
#!/usr/bin/perl
#
# Name:
# read-several.pl.
#
# Purpose:
# Use Image::Magick to read in and process several images.
#
# Author:

# http://savage.net.au/index.html

use strict;
use warnings;

use Image::Magick;

# ---------------------------------------------------------

print "Image::Magick V $Image::Magick::VERSION. \n";
print "\n";
my($dir_name) = '/Scripts/ImageMagick';
chdir($dir_name) || die("Can't chdir($dir_name): $!");
opendir(INX, '.') || die("Can't opendir(.): $!");

closedir(INX);
my($file_count) = $#file_name + 1;
my($image) = Image::Magick -> new();

die $result if $result;
my($image_count) = $#{$image} + 1;

print "File count:  $file_count. \n";
print "Image count: $image_count. \n";
print "\n";
print map{"$_. File: $file_name[$_]. \n"} 0 .. $#file_name;
print "\n";

for (0 .. $#{$image})
{
 my($magick, $file_name, $width, $height) = $$image[$_] -> Get('magick', 'base-filename', 'width', 'height');
 print "$_. $magick. Image: $file_name. Size: $width x $height. \n";

Quote:
}

-----><8-----

However, there seems to be a bug in V 5.42 of Image::Magick, in that I get 1 image too many. I will report it now. My output is:

-----><8-----
Image::Magick V 5.42.

File count:  11.
Image count: 12.

0. File: animated-image.gif.
1. File: big-blue-butt.gif.
2. File: big-blue-butt.png.
3. File: bluebutton.png.
4. File: grin.gif.
5. File: model.gif.
6. File: piddle.gif.
7. File: ronsLogo.gif.
8. File: shadow.gif.
9. File: small-blue-butt.png.
10. File: smile.gif.

0. GIF. Image: animated-image.gif. Size: 48 x 48.
1. GIF. Image: animated-image.gif. Size: 48 x 48.
2. GIF. Image: big-blue-butt.gif. Size: 117 x 36.
3. PNG. Image: big-blue-butt.png. Size: 117 x 36.
4. PNG. Image: bluebutton.png. Size: 117 x 36.
5. GIF. Image: grin.gif. Size: 48 x 48.
6. GIF. Image: model.gif. Size: 128 x 192.
7. GIF. Image: piddle.gif. Size: 300 x 300.
8. GIF. Image: ronsLogo.gif. Size: 152 x 84.
9. GIF. Image: shadow.gif. Size: 300 x 100.
10. PNG. Image: small-blue-butt.png. Size: 117 x 18.
11. GIF. Image: smile.gif. Size: 48 x 48.
-----><8-----



Mon, 19 Jul 2004 07:16:43 GMT  
 Image::Magick: find the last image read
On Wed, 30 Jan 2002 16:53:05 -0600,

Quote:

>>> Or maybe it is possible to insert an object of single image into an object
>>> of multiple image?
>>Sorry, I have trouble parsing this question...

> I mean, read it into an empty Image::Magick object, do the changes, and
> then insert the object to another existing Image::Magick object that act
> as collector.

> It seems that using push will be enough to do that, right?

Yes.

www.imagemagick.org[1] has HTML documentation online about the use of
PerlMagick, and the Image::Magick objects. This documentation is also
distributed as part of the ImageMagick distribution. It includes
examples of doing exactly this:

\begin{quote}

Other clever things you can do with a PerlMagick objects include
    $i = $#$p"+1";   # return the number of images associated with object p


    p->Convolve([1, 2, 1, 2, 4, 2, 1, 2, 1]); # 3x3 Gaussian kernel

\end{quote}

Martien

[1] At the moment I can't see that server in the DNS, but it is
definitely the right one.
--
                                |
Martien Verbruggen              | If it isn't broken, it doesn't have
Trading Post Australia Pty Ltd  | enough features yet.
                                |



Mon, 19 Jul 2004 09:44:47 GMT  
 Image::Magick: find the last image read
On Thu, 31 Jan 2002 10:16:43 +1100,

Quote:
> However, there seems to be a bug in V 5.42 of Image::Magick, in that
> I get 1 image too many. I will report it now. My output is:
> Image::Magick V 5.42.

I can't reproduce that bug for Image::Magick V 5.42 (installed from
5.4.2-3 distribution), Perl 5.6.1 built for i586-linux. If you have an
older 5.4.2 maybe it's already been fixed.

Martien
--
                                |
Martien Verbruggen              | I used to have a Heisenbergmobile.
Trading Post Australia Pty Ltd  | Every time I looked at the
                                | speedometer, I got lost.



Mon, 19 Jul 2004 09:51:52 GMT  
 Image::Magick: find the last image read
Martien

See below.

--
Cheers
Ron Savage

http://savage.net.au/index.html

Quote:

> On Thu, 31 Jan 2002 10:16:43 +1100,

> > However, there seems to be a bug in V 5.42 of Image::Magick, in that
> > I get 1 image too many. I will report it now. My output is:
> > Image::Magick V 5.42.

> I can't reproduce that bug for Image::Magick V 5.42 (installed from
> 5.4.2-3 distribution), Perl 5.6.1 built for i586-linux. If you have an
> older 5.4.2 maybe it's already been fixed.

You're right. I have V 5.4.2 with no 'funny' suffix. enigma tells me my demo runs ok with 5.4.3 beta.


Tue, 20 Jul 2004 07:09:07 GMT  
 Image::Magick: find the last image read

Quote:

> On Wed, 30 Jan 2002 15:59:58 -0600,

[snip]
> $im->[3]->Rotate($angle);
> $im->[0]->Blur($blur_amount);

> > Or maybe it is possible to insert an object of single image into an
> > object of multiple image?

> Sorry, I have trouble parsing this question...

I think he wants something like:

my $im = = Image::Magick->new();
# Do things with the $im object that create images
my $insert_this = Image::Magick->new()
# Do things with $insert_this so it's a new, single image.

--
A child of 5 could understand this!  Fetch me a child of 5



Tue, 20 Jul 2004 17:40:22 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Image::Magick: find the last image read

2. Image Magick finding image size without loading image

3. Converting images without Image::Magick

4. Merging and splitting of images with Image::Magick

5. convert jpg-images to tiff format with image-magick on winnt

6. Image Magick and returning images to a web page

7. AS Perl 629 Image::Magick makes Perl crash when outputting image to file

8. Image::Magick making images from layers

9. ANNOUNCE: Tutorial # 32: Showcasing Image::Magick (part 2): xml-2-image.pl

10. ANNOUNCE: Tutorial # 31: Showcasing Image::Magick (part 1): text-2-image.pl

11. CGI image generation using Image::Magick

12. Displaying Image::Magick image objects in Perl/Tk?

 

 
Powered by phpBB® Forum Software