Sorry if this topic has already been treated. It's my first time here. Five days that I am searching for a solution but can't find it.
My problem : I am trying to create a Facebook application that takes your profile picture and inserts it into a PNG picture.
Everything is working fine with some profile pictures and with others, I'm getting a black screen where profile picture is supposed to be inserted.
But variables are OK. File paths are OK.
I tried with many different profile pictures. With original photos, it's OK. With some cropped pics, its OK also. And some other won't work. Square cropped pics won't work.
Can someone help me out with that ? ... I'm not sure to understand everything I'm doing...

Many thanks!!!
Here's my image code:
Code: Select all
<?php
//this is the core function.
function create_pic($id,$text,$url){
$img = $_POST["image"];
$image = "visuels/".$img.".png";
// creation of a new image, the final one
$im = imagecreatetruecolor(500,500);
// importing profile picture
$profile = imagecreatefromjpeg($url);
// importing transparent mirror image
$mirror = imagecreatefrompng($image);
//end function getJPEGresolution
// retrieving profile picture size
$sizes = getimagesize($url);
$x_dim = $sizes[0];
$y_dim = $sizes[1];
// mirror transparency is 265x335, so I resize the profile picture
// to fit this size, keeping widht/height ratio
if($x_dim<150 or $y_dim<170){
$mult = max(150/$x_dim,170/$y_dim);
$final_x = $x_dim*$mult;
$final_y = $y_dim*$mult;
}
// pasting the resized profile picture on the final image
imagecopyresampled($im,$profile,250-$final_x/2,240-$final_y/2,0,0,$final_x,$final_y,$x_dim,$y_dim);
// pasting the mirror on the final image
imagecopyresampled($im,$mirror,0,0,0,0,500,500,500,500);
// creating some colors
$color = imagecolorallocate($im, 207, 0, 75);
$shadow = imagecolorallocate($im, 0, 0, 0);
// this is the path of the font I am using
$font = "visuels/font.ttf";
// starting at font size 0
$size = 0;
// boolean variable to determine if the font fits on the picture
$it_fits = true;
// increasing font zize by one unit until it won't fit anymore
do{
$last_dim = $dim;
$size++;
$dim = imageftbbox($size, 0, $font, $text);
if($dim[4]-$dim[6]>300){
$it_fits=false;
}
} while($it_fits);
$center = floor((500-$last_dim[4]+$last_dim[6])/2);
imagettftext($im, $size-1, 0, $center, 100, $shadow, $font, $text);
imagettftext($im, $size-1, 0, $center-1, 100-1, $color, $font, $text);
imagejpeg($im,"temp/".$id.".jpg",100);
header('Content-type:image/jpeg');
imagedestroy($im);
imagedestroy($profile);
imagedestroy($mirror);
}
?>
<?php
// core function: creation of the horror picture
create_pic($uid,$text,$user_image);
My GD Library :
GD Support enabled
GD Version bundled (2.0.34 compatible)
FreeType Support enabled
FreeType Linkage with freetype
FreeType Version 2.2.1
GIF Read Support enabled
GIF Create Support enabled
JPG Support enabled
PNG Support enabled
WBMP Support enabled
XPM Support enabled
XBM Support enabled
scottayy | added syntax tags