Preferred way to copy JPG files from remote server using PHP

I am using PHP to copy a JPG from a remote server to my own server. Is it better to just use a function copy()

or is it better to use jpeg functions? For example:

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

      

-OR -

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

      

What's the best option in terms of speed and memory usage? Also, would there be any difference in the resulting image quality? I must add that this script requires a large number of photos to be copied (usually hundreds, but sometimes it can be several thousand).

Thanks Brian

+2


source to share


1 answer


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



using the functions of the gd library (imagecreatefromjpeg / imagejpeg) will eventually compress the image (maybe, maybe that's smart enough, but not necessary, but probably). If you want to convert images to .png or something, then you want to use gd (or ImageMagick)

+3


source







All Articles