GD Warning: one parameter to a memory allocation multiplication is negative or zero, failing operation gracefully
line 618
####
use strict;
use warnings;
use GD;
#UPDATE: need the following line to have a real 'smooth' resampling
GD::Image->trueColor(1);
my $file = $ARGV[0];
die "Please feed a jpg file.." unless -e $file;
my $orig_gd = GD::Image->new($file);
my $photo_ratio = 0.3;
my $small_w = int($orig_gd->width * $photo_ratio);
my $small_h = int($orig_gd->height * $photo_ratio);
draw_photo ($file);
################################################################################
sub draw_photo {
my $file_path = shift;
# create the resized but still empty GD image
my $resized = GD::Image->new($small_w,$small_h);
# copy from source into resized on
$resized->copyResampled($orig_gd,0,0,0,0,
$small_w,
$small_h,
$orig_gd->width,
$orig_gd->height);
# save
open my $out, '>', time.'.jpg' or die "unable to open for write";
binmode $out;
print $out $resized->jpeg or die "unable to write jpg data!";
close $out;
}
##
##
# @files is ArrayOfArray
# each element contains pic data as follow:
# 0 path
# 1 x
# 2 y
# 3 orientation
# 4 datetime joined with underscores
# 5 GD object of THUMB
# 6 [ GD object of PHOTO]
# the last field [6] will be filled only for current file ( which index is hold in $ph_index)
# and for elelments to be preloaded: from ($ph_index - $preload) to ($ph_index + $preload)
# thumb data [5] will be empty if $nothumbs is defined via -nothumbs commandline switch
################################################################################
sub draw_photo {
my $ph_index = shift;
print "\tdraw_photo got:\n\t",(join '|',map{defined $_ ? $_ : 'undef'}
(@{$files[$ph_index]}[0..4],
$files[$ph_index]->[5]?'THUMB':'NO DATA',
$files[$ph_index]->[6]?'PHOTO':'NO DATA',
)),"\n" if $debug;
$tk_ph_image->delete if $tk_ph_image->blank;
# some tk stuff removed
my $small_w = int($files[$ph_index]->[1] * $ph_ratio);
my $small_h = int($files[$ph_index]->[2] * $ph_ratio);
# create the resized but still empty GD image
my $resized = GD::Image->new($small_w,$small_h);
# copy from source into resized on
# NOTE $files[$ph_index]->[6] containf the GD object
$resized->copyResampled($files[$ph_index]->[6],0,0,0,0,
$small_w,
$small_h,
$files[$ph_index]->[6]->width,
$files[$ph_index]->[6]->height);
$tk_ph_image->configure( -file => undef,
-data => MIME::Base64::encode($resized->jpeg())
);
# configure the Tk::Label to use the Tk::Photo as image
$photo_label->configure(-image => $tk_ph_image );
# some display and tk stuff removed
}
################################################################################