Hello
Bod,
letting apart the humor (which incidentally make your post harder to understand for non native english speakers.. :), you never set $resize background to white! I didnt follow all your geometry calculus, but be aware the the default background for a GD image is black:
perl -MGD -e"$im = new GD::Image(100,100);open $fh,'>','out.jpg';binmo
+de $f; print $fh $im->jpeg"
The above print a nice black image.
Simplfying the whole I think you can start from something like the following code, which does what you are looking for
use strict;
use warnings;
use GD;
GD::Image->trueColor(1);
# gray image 100x100
my $im_gray = new GD::Image(100,100);
my $gray = $im_gray->colorAllocate(127,127,127);
$im_gray->filledRectangle(0, 0, 100,100, $gray);
open my $fh_gray,'>','gray.jpg';
binmode $fh_gray;
print $fh_gray $im_gray->jpeg;
# red image 100x100
my $im_red = new GD::Image(100,100);
my $red = $im_red->colorAllocate(255,0,0);
my $black = $im_red->colorAllocate(0,0,0);
$im_red->filledRectangle(0, 0, 100,100, $red);
# with a black circle
$im_red->ellipse(50,50,100,100,$black);
open my $fh_red,'>','red.jpg';
binmode $fh_red;
print $fh_red $im_red->jpeg;
# copy resized red image scaled 50% and centered inside the gray one
$im_gray->copyResized($im_red,25,25,0,0,50,50,100,100);
open my $fh_both,'>','both.jpg';
binmode $fh_both;
print $fh_both $im_gray->jpeg;
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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.