Home > Archive > PERL Miscellaneous > September 2006 > ImageMagick and Perl
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
ImageMagick and Perl
|
|
| kjhjhjhjadsasda@urbanhabit.com 2006-09-28, 6:59 pm |
| Hi,
Im trying to get ImageMagick working on my VPS. Below code used to work
on a previous VPS, but now all I get written is $file1, never $file2.
Problem is, I dont even know how to debug it... Any clues?
$url="someimage.jpg";
$file1="pathonmyserver/something1.jpg";
$file2="pathonmyserver/something2.jpg";
my $response=LWP::UserAgent->new->get($url,':content_file'=>$file1);
$img=Image::Magick->new;
$img->Read($file1);
$img->Scale(geometry=>'548x308');
$img->Resize(width => 548, height => 308);
$img->Write(filename=>$file2);
undef $img;
Thanks!
| |
| usenet@DavidFilmer.com 2006-09-29, 3:59 am |
| kjhjhjhjadsasda@urbanhabit.com wrote:
> on a previous VPS, but now all I get written is $file1, never $file2.
Ummm, that's because you never read or write $file2.
--
David Filmer (http://DavidFilmer.com)
| |
| Gunnar Hjalmarsson 2006-09-29, 3:59 am |
| kjhjhjhjadsasda@urbanhabit.com wrote:
> Im trying to get ImageMagick working on my VPS. Below code used to work
> on a previous VPS, but now all I get written is $file1, never $file2.
> Problem is, I dont even know how to debug it... Any clues?
First clue:
use strict;
use warnings;
<snip>
> $img->Write(filename=>$file2);
my $err = $img->Write($file2) and die $err;
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
| |
| Michele Dondi 2006-09-29, 7:59 am |
| On 28 Sep 2006 16:36:18 -0700, kjhjhjhjadsasda@urbanhabit.com wrote:
>Im trying to get ImageMagick working on my VPS. Below code used to work
>on a previous VPS, but now all I get written is $file1, never $file2.
>Problem is, I dont even know how to debug it... Any clues?
[snip]
>$img->Write(filename=>$file2);
How 'bout checking the return value of Write(), which should be the
number of images (successfully) written?
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{po
p^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
| |
| zentara 2006-09-29, 7:59 am |
| On 28 Sep 2006 16:36:18 -0700, kjhjhjhjadsasda@urbanhabit.com wrote:
>Hi,
>
>Im trying to get ImageMagick working on my VPS. Below code used to work
>on a previous VPS, but now all I get written is $file1, never $file2.
>Problem is, I dont even know how to debug it... Any clues?
>
>$url="someimage.jpg";
>$file1="pathonmyserver/something1.jpg";
>$file2="pathonmyserver/something2.jpg";
>
>my $response=LWP::UserAgent->new->get($url,':content_file'=>$file1);
>$img=Image::Magick->new;
>$img->Read($file1);
>$img->Scale(geometry=>'548x308');
>$img->Resize(width => 548, height => 308);
>$img->Write(filename=>$file2);
>undef $img;
>
>Thanks!
Here is a thumbnail script, written by Merlyn, which shows how
to use IM in a loop cleanly, and see the error messages if any.
It's a bit tricky.
#!/usr/bin/perl
# by Merlyn
use strict;
use Image::Magick;
my $im = Image::Magick->new;
umask 0022;
my @names = @ARGV ? @ARGV : grep { -f and -B } <*>;
for (@names) {
if (/ /) {
my $old = $_;
tr, ,_,s;
$_ .= ".jpg" unless /\.jpg$/;
!-e and rename $old, $_ or next;
warn "renaming $old to $_\n";
}
next if /\.thumb\.jpg$/;
my $thumb = "$_.thumb.jpg";
next if -e $thumb;
undef @$im;
my $ret;
$ret = $im->Read($_)
and warn($ret), next;
$ret = $im->Scale( geometry => '100x100' )
and warn($ret), next;
$ret = $im->Write($thumb)
and warn($ret), next;
warn "thumbnail made for $_\n";
}
__END__
--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
| |
| Gunnar Hjalmarsson 2006-09-29, 7:59 am |
| Michele Dondi wrote:
> On 28 Sep 2006 16:36:18 -0700, kjhjhjhjadsasda@urbanhabit.com wrote:
>
> [snip]
>
>
> How 'bout checking the return value of Write(), which should be the
> number of images (successfully) written?
Are you sure of that? Please see the examples posted by me and zentara.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
| |
| Michele Dondi 2006-09-29, 6:59 pm |
| On Fri, 29 Sep 2006 14:02:45 +0200, Gunnar Hjalmarsson
<noreply@gunnar.cc> wrote:
>
>Are you sure of that? Please see the examples posted by me and zentara.
No, but that's what's written in the documentation.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{po
p^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
| |
|
|
|
|
|