PHP GetImageSize determining network Image types This post was last edited by ciscole at 2013-09-02$ data & nbsp ;=& nbsp; GetImageSize ($ logoUrl); & nbsp; if & nbs PHP's question about how to determine the network Image type of GetImageSize
This post was last edited by ciscole at 14:39:26
$data = GetImageSize($logoUrl);
if $data[2] =='1' {
$logo = ImageCreateFromGIF($logoUrl);
}
else if $data[2] =='2' {
$logo = ImageCreateFromJPEG($logoUrl);
}
else {
$logo = ImageCreateFromPNG($logoUrl);
}
Is it wrong for me to write this? How should I write it! Learning php for two days
The problem I want to solve is as follows:
Is an image URL, the image URL format is roughly such a http://www.x.com/logo.php? XXXXXX (no extension)
This image may be jpg, gif, or png.
What should I do! Share:
------ Solution --------------------
This is correct, but not strict.
If it's not 1 or 2, is it png? Isn't it anything else?
Because you are processing network images, you need to access the same image twice in a very short gap, which can easily trigger the alert of anti-Leech.
In addition, the network is complex, and it cannot be said that both of them will succeed.
This is better written.
if($s = file_get_contents($logoUrl)) {
$logo = imagecreatefromstring($s);