GD seems to have various imagecreatefrom_x_ functions which is great if you know the image type ahead of time. In my particular situation, I don’t. Is there a way to read in the image without knowing the type?
My only option so far is to save it to disk (expensive!) and then use getimagesize (which also provides mime type) – but this results in me reading in the image twice – once to determine the MIME type and then again to read it into GD.
Alternatively, is it possible to just treat a variable as a file? something like this:
$image = file_get_contents('http://the.remote.file.com/myfile');
# doesn't work with already read in image ... can I treat this as a file w/o saving it?
$info = getimagesize($image);
You can use
imagecreatefromstring(), which is indifferent to the actual file format and the best option if you’ve read in the file already.But for practical purposes you should be able to use
getimagesize($filename). You don’t have to read in the file before. Just use the filename or url.