简体   繁体   English

从URL用php创建png图像

[英]create png image with php from an URL

How to create PNG image with given width and height from an image URL. 如何从图像URL创建具有给定宽度和高度的PNG图像。 i was trying with this code. 我正在尝试使用此代码。 but getting an invalid picture: 但得到无效的图片:

$img_r = imagecreatefrompng($src);
$dst_r = ImageCreateTrueColor( $targ_w, $targ_h );
imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'],$targ_w,$targ_h,$_POST['w'],$_POST['h']);
header('Content-type: image/png');
@imagepng($dst_r, url_to_save, $jpeg_quality);

首先,我将从网址(file_get_contents / curl / etc)中获取文件,然后将其写入磁盘,并确定它是否是图像,什么类型等,然后,我会努力工作并使用图像处理库,例如http:/ /phpthumb.gxdlabs.com/调整图像大小并保存为我想要的图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM