如何从PHP上传URL中的图像

Jas*_*vis 6 php gd imagemagick image-processing

在使用GD或imagemagick的PHP中我如何从URL上传照片,我想构建一个函数,我可以通过一些参数传递并上传图像,我可以将一个大图像上传,将其调整为较小,然后调整一些关闭它的更多缩略图并将所有位置保存到1个图像的位置但是我想添加从URL获取图像然后在其上运行我的代码以调整大小和制作拇指的功能.

我会使用卷曲或其他任何例子或想法将不胜感激

Ali*_*xel 11

$image = @ImageCreateFromString(@file_get_contents($imageURL));

if (is_resource($image) === true)
{
    // image is valid, do your magic here
}

else
{
    // not a valid image, show error
}
Run Code Online (Sandbox Code Playgroud)

@两个功能,以防止有PHP从引发错误如果URL不是有效的图像.