Hello estimated monks!

I recently released picwoodpecker which latest version with a minor fix is on github.

It seems the program does not run well on Linux (it was developped and tested on win7 only).

With a bit of pain i'v set up a Linux Ubuntu 16.04 LTS 32 bit as a virtual machine using virtualbox.

The problem arise when the application try to use the copyResampled GD method:

GD Warning: one parameter to a memory allocation multiplication is neg +ative or zero, failing operation gracefully line 618

The Ubuntu machine has perl 5.22 and GD version is 2.53

I've tryed to reduce the problem to the simplest one and I ended with the following:

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; }

The above runs fine on my win7 machine (perl 5.14 GD 2.46) and creates a resampled image.

It also creates a resampled image on Ubuntu so it does not complains about the zeros! So i'm stucked and seek for your wisdom.

The relevant part of the original code that fails on Linux is the following:

# @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 inde +x 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 c +ommandline 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->jpe +g()) ); # configure the Tk::Label to use the Tk::Photo as image $photo_label->configure(-image => $tk_ph_image ); # some display and tk stuff removed } ###################################################################### +##########

Thanks for your patience

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

In reply to resampling an image using GD not working on Linux by Discipulus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.