Brian
Brian

Reputation: 2147

Preferred way to copy JPG files from a remote server using PHP

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

Upvotes: 2

Views: 1341

Answers (1)

timdev
timdev

Reputation: 62894

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)

Upvotes: 3

Related Questions