ProblemHelpPlease Posted August 26, 2009 Share Posted August 26, 2009 I need to check the size of a remote image and adjust the width and height html tags if it is too big before the page loads. I have looked at using getimagesize in php but this doesnt work on a remote image as I have allow_url_fopen=off due to recent security problems.Does anyone have any ideas of another way to do this? Link to comment Share on other sites More sharing options...
ProblemHelpPlease Posted August 26, 2009 Author Share Posted August 26, 2009 I have found a solution using CURL meaning I am able to keep allow_url_fopen=off in place. Link to comment Share on other sites More sharing options...
ProblemHelpPlease Posted August 26, 2009 Author Share Posted August 26, 2009 Solution I have works ok but I have a question about image types. I am using the piece of code below and it seems to work fine for all jpg gif and png but should I be using the imagejpg command when the image is an unknown image from a remote server that maybe jpg gif or png. imagejpeg($new_image, $tempfile,100); Link to comment Share on other sites More sharing options...
justsomeguy Posted August 26, 2009 Share Posted August 26, 2009 Why is it unknown? Can't you figure out what it is? Link to comment Share on other sites More sharing options...
ProblemHelpPlease Posted August 26, 2009 Author Share Posted August 26, 2009 I could determine what the file extensions was but as it appears to work with any extensions I wonder if I need to bother. I am creating a temporary file on my server from the file on the remote server purley to gain width and height of the remote image. I don't actually display the created image, I display the remote one with the height and width tags set to the relevant size. Link to comment Share on other sites More sharing options...
justsomeguy Posted August 26, 2009 Share Posted August 26, 2009 If you're using CURL to just read the file's data and you have that in a string, you can get the dimensions like this without needing to write a new file:$image = imagecreatefromstring($curl_data);$w = imagesx($image);$h = imagesy($image); Link to comment Share on other sites More sharing options...
ProblemHelpPlease Posted August 26, 2009 Author Share Posted August 26, 2009 Thanks for that, works beautifully and solves the file extension problem. I didn't realise that I could get the file size without needing to create a temporary file first. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.