$p = scandir(storage_path('pdf_xls_temp/stamps'));
mkdir(storage_path('pdf_xls_temp/sub_stamps'));
foreach($p as $val){
//排除目录中的.和..
if($val !="." && $val !="..") {
$source_path = storage_path('pdf_xls_temp/stamps/'.$val);
$dest_path = storage_path('pdf_xls_temp/sub_stamps/'.$val);
$source = imagecreatefrompng($source_path);
imagesavealpha($source,true);//这里很重要 意思是不要丢了$sourePic图像的透明色;
list($src_w,$src_h)=getimagesize($source_path);
$h = 320;
$w = 450;
$im = imagecreatetruecolor($w, $h);
imagealphablending($im,false);//这里很重要,意思是不合并颜色,直接用$img图像颜色替换,包括透明色;
imagesavealpha($im,true);//这里很重要,意思是不要丢了$thumb图像的透明色;
imagecopy($im,$source,0,0,($src_w-$w)/2,($src_h-$h)/2,$w,$h);
imagepng($im, $dest_path);
imagedestroy($source);
imagedestroy($im);
}
}
mark一下,自己以后可能用得到,从A4纸透明背板图片,截取了中心的关键图像(尺寸与截取起始点位置可调),清晰度肉眼看没有改变,而且保留了透明背板,没有变成黑色或者白色(亲测普通图片也可以剪切)
这里素材是像素 1653 X 2338,位深度32的png-24图片,印章居中,背板透明