使用 PHP 从远程服务器复制 JPG 文件的首选方法

发布于 2024-08-08 08:07:38 字数 380 浏览 2 评论 0原文

我正在使用 PHP 将 JPG 从远程服务器复制到我自己的服务器。最好是简单地使用 copy() 函数,还是 jpeg 特定的函数更好?例如:

$copy = copy($remote_url, $dest_file);

-或-

$img = imagecreatefromjpeg($remote_url);
$copy = imagejpeg($img, $dest_file);
imagedestroy($img);

就速度和内存负载而言,最佳选择是什么?另外,最终的图像质量会有什么差异吗?我应该补充一点,这个脚本需要复制大量照片(通常是数百张,但有时可能是几千张)。

谢谢,布莱恩

I'm using PHP to copy JPGs from a remote server to my own server. Is it best to simply use the copy() function, or are the jpeg-specific functions better? For example:

$copy = copy($remote_url, $dest_file);

-OR-

$img = imagecreatefromjpeg($remote_url);
$copy = imagejpeg($img, $dest_file);
imagedestroy($img);

What would the best option be in terms of speed and memory load? Also, would there be any difference in the resulting image quality? I should add that this script is required to copy a large number of photos (typically hundreds, but sometimes it may be a couple thousand).

Thanks, Brian

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

彼岸花ソ最美的依靠 2024-08-15 08:07:38

如果您想要的只是一个副本,则 copy() 更好。

使用 gd 库函数(imagecreatefromjpeg/imagejpeg)最终会重新压缩图像(可能,也许它足够聪明,不会这样做,但可能)。如果您想将图像转换为 .png 或其他格式,那么您需要使用 gd (或 ImageMagick)

if all you want is a copy, copy() is better.

using the gd library functions (imagecreatefromjpeg/imagejpeg) will end up re-compressing the image (probably, maybe it's smart enough not to, but probably). If you wanted to convert the images to .png or something, then you'd want to use gd (or ImageMagick)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文