如何保存由PHP图像复制合并功能创建的图像


How to save image created by PHP imagecopymerge function

code:

$dest = @imagecreatefrompng(base_url().'assets/images/card-design-3-backside.png');
$src = @imagecreatefrompng(base_url().'assets/images/card-design-3-ackside.png);
$sj = imagecopymerge($dest, $src, 845, 280, 0, 0, 200, 200, 100);    
header('Content-Type: image/png');          
imagepng($dest);
imagedestroy($dest);
imagedestroy($src);

如果你想将图像保存到文件中,只需将第二个参数添加到imagepng((函数中。喜欢这个:

imagepng($dest, "file.png");

不需要添加标头,因为我们不想输出到浏览器。

大概你的意思是保存到磁盘或下载。从手册:

保存到磁盘(在服务器上(:

<?php
// Create a destination
$dest = 'new/spot/new_name.png';
// Get contents from original spot
$im = imagecreatefrompng("https://www.fagario.com/skins/by-hacker.png");
// Save to disk in the new spot and name
imagepng($im,$dest);
// Destroy image
imagedestroy($im);

下载(到本地(:

<?php
$dest   =   "name.png";
// Get contents from original spot
$im = imagecreatefrompng("https://www.fagario.com/skins/by-hacker.png");
header('Content-Disposition: Attachment; filename='.$dest); 
// Create the proper file type header
header('Content-Type: image/png');
imagepng($im);
// Destroy image
imagedestroy($im);

存在于浏览器中(无法下载或保存(:

<?php
// Get contents from original spot
$im = imagecreatefrompng("https://www.fagario.com/skins/by-hacker.png");
// Create the proper file type header
header('Content-Type: image/png');
imagepng($im);
// Destroy image
imagedestroy($im);