###################### # Upload artwork image sub XHRupload { no strict 'subs'; my $full; my $image = Image::Resize->new(GD::Image->new($file{'joolzimage', 'file'})); if ($image->width() > 1800) { $full = $image->resize(1800, 99999); } else { $full = $image->gd(); } my $year = (localtime)[5] + 1900; my $watermark = 'Artwork by Joolz'; my $copyright = "copyright $year"; # Centre text components on image my $colour = $full->colorAllocate(0, 0, 0); my @bounds = new GD::Image->stringFT($colour, "$ENV{'DOCUMENT_ROOT'}/cgi-bin/Image/outline.ttf", 90, 0.18, 0, 0, $watermark); my $left = ($full->width() / 2) - (($bounds[2] - $bounds[0]) / 2) + 5; my $top = ($full->height() / 2) - ($bounds[7] - $bounds[1]) / 2; # Select colour my ($rd, $gn, $bl) = (0, 0, 0); for (my $x = $left; $x < $left + ($bounds[2] - $bounds[0]); $x += 20) { for (my $y = $top - 450; $y < $top + 130; $y += 20) { my ($r, $g, $b) = $full->getPixel($x, $y); $bl = 255 - $r if 255 - $r > $rd; $rd = 255 - $g if 255 - $g > $gn; $gn = 255 - $b if 255 - $b > $bl; } } $rd = 120 if $rd > 120; $gn = 120 if $gn > 120; $bl = 120 if $bl > 120; $colour = $full->colorAllocate($rd, $gn, $bl); $full->stringFT($colour, "$ENV{'DOCUMENT_ROOT'}/cgi-bin/Image/outline.ttf", 90, 0.18, $left, $top, $watermark); @bounds = new GD::Image->stringFT($colour, "$ENV{'DOCUMENT_ROOT'}/cgi-bin/Image/watermark.ttf", 95, 0.18, 0, 0, $copyright); $left = ($full->width() / 2) - (($bounds[2] - $bounds[0]) / 2) + 5; $full->stringFT($colour, "$ENV{'DOCUMENT_ROOT'}/cgi-bin/Image/watermark.ttf", 95, 0.18, $left, $top + 160, $copyright); open my $fh, '>', "$ENV{'DOCUMENT_ROOT'}/artwork/full/$data{'id'}.jpg"; print $fh $full->jpeg(100); close $fh; my $thumb = $image->resize(300, 1000); open $fh, '>', "$ENV{'DOCUMENT_ROOT'}/artwork/thumbs/$data{'id'}.jpg"; print $fh $thumb->jpeg(32); close $fh; print "Content-type: text/plain\n\n"; print $data{'id'}; exit 0; }