function merge($width, $height) { $array_variable = get_variable(); $bg = $array_variable[0]; $over = $array_variable[1]; $outputFile = $array_variable[2]; $result = $array_variable[3]; $path_to_save = $array_variable[4]; $n = $array_variable[5]; $tmp_img = $path_to_save . "/tmp_" . $n . ".png"; // $result_jpg_compressed = $path_to_save.'/'.$n.'.JPG'; // $base_image = imagecreatefrompng($bg); jpg2png($bg, $outputFile); $base_image = imagecreatefrompng($outputFile); $top_image = imagecreatefrompng($over); // $merged_image = $result; imagesavealpha($top_image, true); imagealphablending($top_image, true); imagecopy($base_image, $top_image, 0, 0, 0, 0, $width, $height); imagepng($base_image, $result); // rename to temp for compression rename($result, $path_to_save . "/tmp_" . $n . ".png"); // compress IMG $img = imagecreatefrompng($tmp_img); // imagejpeg($img,$result_jpg_compressed,75); imagejpeg($img, $result, 75); unlink($tmp_img); unlink($tmp_img); // if necessery !!!!!!!!!!!!!!!!!!! unlink($outputFile); unlink($over); }
function merge($width, $height) { $nowtime = time(); $array_variable = get_variable(); $bg = $array_variable[0]; $over = $array_variable[1]; $outputFile = $array_variable[2]; $result = $array_variable[3]; $path_to_save = $array_variable[4]; $n = $array_variable[5]; $tmp_img_rezized = $path_to_save . "/tmp_" . $nowtime . ".jpg"; $tmp_img = $path_to_save . "/tmp_" . $n . ".png"; // $result_jpg_compressed = $path_to_save.'/'.$n.'.JPG'; // resize_image //$bg = resize_image($bg, $width, $width); // smart_resize_image($bg,null,$width,$height,false,$tmp_img_rezized,true); //copy($bg, $tmp_img_rezized); // smart_resize_image($tmp_img_rezized,$width,$height); list($orwidth, $orheight) = getimagesize($bg); //$filename = $path_to_save.'/toto.jpg'; $tmp = imagecreatetruecolor($width, $height); //$source = imagecreatefromjpeg($tmp_img_rezized); $source = imagecreatefromjpeg($bg); imagecopyresampled($tmp, $source, 0, 0, 0, 0, $width, $height, $orwidth, $orheight); imagejpeg($tmp, $tmp_img_rezized, 70); // Chargement // $thumb = imagecreatetruecolor($newwidth, $newheight); //$source = imagecreatefromjpeg($filename); // Redimensionnement //imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); // $base_image = imagecreatefrompng($bg); // $bg = $tmp_img_rezized; // jpg2png($bg, $outputFile); jpg2png($tmp_img_rezized, $outputFile); $base_image = imagecreatefrompng($outputFile); $top_image = imagecreatefrompng($over); // $merged_image = $result; imagesavealpha($top_image, true); imagealphablending($top_image, true); imagecopy($base_image, $top_image, 0, 0, 0, 0, $width, $height); imagepng($base_image, $result); // rename to temp for compression rename($result, $path_to_save . "/tmp_" . $n . ".png"); // compress IMG $img = imagecreatefrompng($tmp_img); // imagejpeg($img,$result_jpg_compressed,75); imagejpeg($img, $result, 75); @unlink($tmp_img); @unlink($tmp_img_rezized); // if necessery !!!!!!!!!!!!!!!!!!! @unlink($outputFile); @unlink($over); }