My goal is to select an area from the existing photo and then save it. Right now I'm stuck on the gdImageCreateFromGd2Part function. Here is the actual chunk of code that I'm running. I'm going to have two parts, which execute depending on if the image has more or less than 4 million pixels. If it has less than that number, it uses copyResized. This part works. I'm working on the part that processes images with more than that many pixels. The code works fine apart from the line with the gdImageCreateFromGd2Part function in it. Hope this more detailed code helps:
my $srcimage = GD::Image->newFromJpeg($target_dir."/".$newName); my ($srcW,$srcH) = $srcimage->getBounds(); if( $srcW*$srcH > 4000000 ){ my $newimage = new GD::Image(100,100); $newimage->gdImageCreateFromGd2Part($srcimage,100,100,100,100); # future code to make a thumbnail from the part that is pulled fro +m the image }else{ my $maxheight = 400; my $maxwidth = 400; my $wdiff = $srcW - $maxwidth; my $hdiff = $srcH - $maxheight; my $newH; my $newW; if ($wdiff > $hdiff){ $newW = $maxwidth; $aspect = ($newW/$srcW); $newH = int($srcH * $aspect); }else{ $newH = $maxheight; $aspect = ($newH/$srcH); $newW = int($srcW * $aspect); } my $newimage = new GD::Image($newW,$newH); $newimage->copyResized($srcimage,0,0,0,0,$newW,$newH,$srcW,$srcH); open(FILE, ">".$target_dir."/preview/".$newName) || die "Cannot op +en image: $!\n"; print FILE $newimage->jpeg; }

In reply to Re^2: gdImageCreateFromGd2Part by Anonymous Monk
in thread gdImageCreateFromGd2Part by sfhazel

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.