ImageCreateFromString and getimagesize in PHP

Currently, if a POST / user uploads a photo to my PHP script, I start with code like this

getimagesize($_FILES['picture1']['tmp_name']);

Then I do LOT more material, but I also try to get the photo from the URL and process it with a different code if I can. So I want to know, I'm using something like this

$image = ImageCreateFromString(file_get_contents($url));

Can I then run getimagesize () in my $ image variable?



UPDATE

I just tried this ...

$url = 'http://a0.twimg.com/a/1262802780/images/twitter_logo_header.png';
$image = imagecreatefromstring(file_get_contents($url));
$imageinfo = getimagesize($image);
print_r($imageinfo);

But he did not work, gave it.

Warning: getimagesize(Resource id #4) [function.getimagesize]: failed to open stream: No such file or directory in

Any idea how I can do this or something like that to get the result I get after?

+3
source share
4 answers

I suggest you follow this approach:

// if you need the image type
$type = exif_imagetype($url);

// if you need the image mime type
$type = image_type_to_mime_type(exif_imagetype($url));

// if you need the image extension associated with the mime type
$type = image_type_to_extension(exif_imagetype($url));

// if you don't care about the image type ignore all the above code
$image = ImageCreateFromString(file_get_contents($url));

echo ImageSX($image); // width
echo ImageSY($image); // height

exif_imagetype() , getimagesize(), ImageSX()/ImageSY(), , .

, getimagesize() URL- , , exif_imagetype(), PHP Manual:

, . , getimagesize() 2, exif_imagetype() .

, exif_imagetype() .

+10

, , imagesx imagesy.

+1

getimagesize HTTP.

. ( ) .

,

$info = getimagesize($url);
$image = ImageCreateFromString(file_get_contents($url));

.

0

, , , , , , http- .

. .

BTW: , , file_get_contents() URL-, !

0

Source: https://habr.com/ru/post/1727714/


All Articles