Jump to content
  • Advertisement
Sign in to follow this  

Retrieving Remote Image Properties in PHP

This topic is 4503 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to create a forum, and have a feature that will allow users to display an avatar from a remote location, so they don't have to upload it. I want the image to have certain dimension size limits, and if the remote image exceeds the limit, the image tag will display the image in the maximum dimensions. Is there a way to retrieve the image dimensions without having to upload it?

Share this post


Link to post
Share on other sites
Advertisement
Depends on the "remote location." If you mean that the image is hosted on another web server, you can write some quick code to do an HTTP HEAD command on the URL and get the image file size. If the image is just on a user's hard drive, I don't think there's a portable way to check the image size without actually uploading to the server. PHP does let you enforce size limits on file uploads fairly easily, though.

[edit] Yayy, I can read! [grin]

Image dimensions aren't generally going to be available unless you have the image locally accessible for your PHP code to examine. An upload to a temporary directory, or a use of file_get_contents for remotely-hosted images, will let you get the file data; then it's just a matter of using the PHP image libraries to examine the image details. No reliable way to probe that remotely, unfortunately.

Share this post


Link to post
Share on other sites
The big problem with remote avatars is abuse. Sure, you can check the size at the time you add the avatar, but the user can swap out the image, or if they're clever, use a script themselves that returns a different image when queried.

So I don't recommend this idea at all. If you're going to have avatars, you might as well store them locally, and limit the filesize. Even if your forum does end up being the next SomethingAwful or something, 15k/user isn't really going to kill anyone.

So it's just not a good idea.

But, if you must, download a copy, check its dimensions, delete it. If it works, say "yay" and move on. If it doesn't, complain and die. That simple.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!