سؤال

I am using JCrop in a project of mine (the user have to crop his face) and send the coordinates & source image to a PHP handler. The flow should be the following: based on the coordinates received the handler crop the image and use imagecopy() to put the newly created image (90x90 in my case) over an empty layout created with ImageCreateTrueColor(). This works fine so far but the next step is: i have to load a png image with a transparent section. (I hope i explain clear enough) which have the same width and height as the previous layout who has the croped area on it. The final step is to use again imagecopy() to put the png over the layout and have as final result the template with the transparent section covered by the crop made by the user. Here is my code:

$targ_w = $targ_h = 90;
$jpeg_quality = 100;
$src = $_POST['s'];
$img_r = imagecreatefromjpeg($src);
$dst_r = ImageCreateTrueColor( $targ_w, $targ_h );
imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'],
$targ_w,$targ_h,$_POST['w'],$_POST['h']);
$layout = ImageCreateTrueColor(459,683);
imagecopy($layout, $dst_r, 263, 249, 0, 0, 90, 90);
$template = 'template.png';
$src_r = imagecreatefrompng($template);
$background = imagecolorallocate($src_r, 255, 255, 255);
imagecolortransparent($src_r, $background);
imagealphablending($src_r, false);
imagesavealpha($src_r, true);
imagecopy($layout, $src_r, 0, 0, 0, 0, 459, 683);
header('Content-type: image/png');
imagepng($src_r);

I've tried many things found online and nothing seems to work. EDIT: The issue is that the transparent section is black instead of being there the cropped face. I really need some advise. Thank you in advance.

هل كانت مفيدة؟

المحلول

I wrote a class before, will it fix your problem? http://www.gdenhancer.com

Here is the example

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top