php imagerotate和imagecopymerge没有透明背景,没有自动宽度/高度

时间:2014-07-17 10:40:58

标签: php transparent

我有这个脚本,它制作一个图像并将其发布在另一个图像上:

<?php
$img=imagecreatetruecolor(150,20);
imagealphablending($img,false);

$col=imagecolorallocatealpha($img,255,255,255,127);
$black = imagecolorallocate($img, 0, 0, 0);
imagecolortransparent($img, $black);
imagefilledrectangle($img,0,0,180,20,$col);
imagealphablending($img,true);
$font='../ttf/0001.ttf';
$color = imagecolorallocate($img, 0, 0, 0);
imagettftext($img,11,0,5,14,$color,$font,'Text goes here'); 
imagealphablending($img,false);
imagesavealpha($img,true);

imagejpeg($img, '../custom_images/test.jpg');
// Create image instances

$dest = imagecreatefromjpeg('../custom_images/121536.jpg');
$src = imagecreatefromjpeg('../custom_images/test.jpg');
$width = imagesx($src);
$height = imagesy($src);
imageantialias($src, true);
$color = imagecolorallocatealpha($src, 0, 0, 0, 127);
$rotated = imagerotate($src, 0, $color);
imagesavealpha($rotated, true);

$trans_colour = imagecolorallocatealpha($rotated, 0, 0, 0, 127);
imagefill($rotated, 0, 0, $trans_colour);

imagepng($rotated, 'shahid.png');
$new_img = imagecreatefrompng('shahid.png');
$width = imagesx($new_img);
$height = imagesy($new_img);

// imagecopymerge($dest, $new_img, 50, 50, 0, 0, $width+60, $height+60, 100);

imagecopymerge_alpha($dest, $new_img, 0, 20, 0, 0, $width, $height, 100);

// Output and free from memory

header('Content-Type: image/png');
imagepng($dest);
imagedestroy($dest);
imagedestroy($src);
?>

2件事:

  1. 背景不透明
  2. 我希望宽度和高度是自动的,所以如果文字很短,那么图像就是它。
  3. 我有什么错?

0 个答案:

没有答案