GD::copyResampled problem on activestate perl

S

surf

I'm using activestate perl 5.8.6

My program below tries to shrink a jpeg file.
The original file is 850 k, and the resulting file is 27 bytes. It's
not working obviously.
I have tried various different ways of creating the img_data via new()
before the
CopyResampled() call.

===========================================

#!/bin/perl


use GD;

my $img = GD::Image->new("JE6001_1.JPG");


($w,$h) = $img->getBounds;

print("$w x $h\n");
$dw = int($w * 0.75);
$dh = int($h * 0.75);
print("$dw x $dh\n");



$img_data = new GD::Image($w,$h);

$img_data->copyResampled($img,0,0,0,0,$dw,$dh,$w,$h);

open(FL, ">x.jpg");
binmode FL;

print FL $img_data;
 
S

surf

oops, sorry I was barking up the wrong tree
I had to put $img_data->jpeg() on the print.
 
P

Paul Lalli

surf said:
My program below tries to shrink a jpeg file.
The original file is 850 k, and the resulting file is 27 bytes. It's
not working obviously.
I have tried various different ways of creating the img_data via new()
before the
CopyResampled() call.

===========================================

#!/bin/perl
use GD;
my $img = GD::Image->new("JE6001_1.JPG");
($w,$h) = $img->getBounds;

print("$w x $h\n");
$dw = int($w * 0.75);
$dh = int($h * 0.75);
print("$dw x $dh\n");

$img_data = new GD::Image($w,$h);
$img_data->copyResampled($img,0,0,0,0,$dw,$dh,$w,$h);

open(FL, ">x.jpg");
binmode FL;

print FL $img_data;

Have you read the documentation for the module you're using? If not,
why not? If so, can you explain what part of

http://search.cpan.org/~lds/GD-2.32/GD.pm#Image_Data_Output_Methods

made you think that printing the object itself would actually print the
image data the object contained, in the JPEG format you were hoping
for?

Paul Lalli
 
A

A. Sinan Unur

My program below tries to shrink a jpeg file.
The original file is 850 k, and the resulting file is 27 bytes. It's
not working obviously.
I have tried various different ways of creating the img_data via new()
before the CopyResampled() call.

===========================================

#!/bin/perl

use strict;
use warnings;

missing.

You have been posting here long enough to know to make sure your code is
strict and warnings clean.
use GD;

my $img = GD::Image->new("JE6001_1.JPG");


($w,$h) = $img->getBounds;

print("$w x $h\n");
$dw = int($w * 0.75);
$dh = int($h * 0.75);
print("$dw x $dh\n");

$img_data = new GD::Image($w,$h);

$img_data = GD::Image->new($dw, $dh);

Note that indirect object notation has its problems.
$img_data->copyResampled($img,0,0,0,0,$dw,$dh,$w,$h);

open(FL, ">x.jpg");
binmode FL;

print FL $img_data;

Did you actually examine what is in the file?

D:\Home\asu1\UseNet\clpmisc> cat x.jpg
GD::Image=SCALAR(0x354cc)

You need to call the jpeg method on the GD::Image object to get jpeg
data. I thought it would have been sensible to examine what got written
to the file, but I guess it is easier to ask others to do that.

#!/usr/bin/perl

use strict;
use warnings;

use GD;

my $src = GD::Image->new('sinan_start.jpg');
my ($w,$h) = $src->getBounds;

print "$w x $h\n";

my ($dw, $dh) = map { int($_ * .75) } ($w, $h);

print("$dw x $dh\n");

my $dest = GD::Image->new($dw, $dh);

$dest->copyResampled($src, 0, 0, 0, 0, $dw, $dh, $w, $h);

open my $dest_h, '>', 'x.jpg'
or die "Cannot write to 'x.jpg': $!";
binmode $dest_h;

print $dest_h $dest->jpeg;

__END__
 
S

surf

Sorry,

I am sometimes impatient and I had tried to work with imager,
image:magick and GD.
I installed imager and then decided to try GD instead. At first I tried
to use
CopyResized and found some posts that said CopyResampled() was better
and someone had
a problem with CopyResized(). I had imagined the file was just
binary garbage until I realized there may be some other method I
omitted.
I was just trying to shrink a jpeg and there was alot of documentation
to go through which
I am still studying. There are alot of perl idioms that still seem
strange to me.
I will look into indirect object notation and what that means. Some of
my books have it listed in the index
but don't refer to it directly that I've found yet.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top