get image size from picture off another web server

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

get image size from picture off another web server

Post by psychotomus »

how can you get the image size of an external picture located on another server?
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

file_get_contents() and filesize()?
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

Post by psychotomus »

how can I get the type of a file?
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

filetype()

Images start with "image/"
i.e. "image/jpeg," "image/gif," "image/pjpeg"
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

if by "image size" you mean the dimensions of the picture, you'll have to load it with imagecreatefromjpeg() (or one of it's brothers) and then use imagesx() and imagesy()
ckh
Forum Newbie
Posts: 9
Joined: Fri Jun 10, 2005 11:15 am

Post by ckh »

I was using getimagesize() to check off site banner sizes to make sure they were a max of 480X60. Something like:

Code: Select all

$size = getimagesize($imageURL);

if ($size[0] > 468 || $size[1] > 60) {
  // Reject it
}
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Just a note: getimagesize() returns a lot of information about a file if it reads as an image to PHP. Dimensions and image type are just a piece of the information returned.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

:banghead:
That would be the easier way.. by far!

Nice one feyd :-)
Post Reply