所以我想拍攝兩張大圖片(但後來我會梳理6張圖片),將它們調整到x,y寬度,我從photoshop拍攝的高度,然後將它們合併合成一張460 x 230大小的圖像。Image GD調整大小問題
這是我使用
<?php
$dest = imagecreatefrompng('https://blzgdapipro-a.akamaihd.net/hero/ana/career-portrait.png');
$src = imagecreatefrompng('https://blzgdapipro-a.akamaihd.net/game/rank-icons/season-2/rank-6.png');
imagealphablending($dest, false);
imagesavealpha($dest, true);
imagealphablending($src, false);
imagesavealpha($src, true);
//imagescale($dest, 396, 161.92);
$some = imagecreate(460, 230);
$dest2 = resize($dest, 396, 162);
$src2 = resize($src, 79.19, 79.19);
//imagecopyresized($dest, $dest, 0, 0, 0, 0, 396, 161.92, 1098, 449);
imagecopyresized($src, $src, 10, 10, 0, 0, 79.19, 79.19, 256, 256);
//$img2 = imagecopymerge($dest, $src, 0, 0, 0, 0, 256, 256, 100); //have to play with these numbers for it to work for you, etc.
imagecopymerge($dest2, $src2, 0, 0, 0, 0, 460, 230, 50);
header('Content-Type: image/png');
imagepng($dest, 'merged2.png');
imagepng($dest2);
//file_put_contents('merged.png', $contents);
imagedestroy($dest);
imagedestroy($src);
imagedestroy($some);
imagedestroy($dest2);
imagedestroy($src2);
imagedestroy($img2);
//imagedestroy($then);
function resize($img, $width, $height, $stretch = false)
{
$temp = imagecreatetruecolor($width, $height);
imagealphablending($temp, true);
imagesavealpha($temp, true);
$bg = imagecolorallocatealpha($temp, 0, 0, 0, 0); // Background color
imagefill($temp, 0, 0, $bg);
if ($stretch)
{
imagecopyresampled($temp, img, 0, 0, 0, 0, $width, $height, imagesx($img), imagesy($img));
}
else
{
if (imagesx($img) <= $width && imagesy($img) <= $height)
{
$fwidth = imagesx($img);
$fheight = imagesy($img);
}
else
{
$wscale = $width/imagesx($img);
$hscale = $height/imagesy($img);
$scale = min($wscale, $hscale);
$fwidth = $scale * imagesx($img);
$fheight = $scale * imagesy($img);
}
imagecopyresampled($temp,
$img,
($width - $fwidth)/2, ($height - $fheight)/2,
0, 0,
$fwidth, $fheight,
imagesx($img), imagesy($img)
);
}
return $temp;
}
,因爲這條線的問題是,呈現的圖像非常褪色 代碼:
imagecopymerge($dest2, $src2, 0, 0, 0, 0, 460, 230, 50);
如果我改變了50,這是PCT值爲100,它顯示一個黑色背景圖像(掩蓋另一個圖像),但如果我將其更改爲0,它只顯示另一個黑色背景圖像(掩蓋另一個圖像) 如果值爲0或100,則顯示的圖像全色。如何將這兩幅圖像合併在一起,同時保持它們的透明度和色彩活力?
我也試過使用這些值:'imagealphablend ($ dest,true);imagesavealpha($ dest,true); imagealphablending($ src,true);imagesavealpha($ src,true); ' –