How to get Picture Sizes?

Any problem with PHP can be disscused here
Flipper3
Posts: 353
Joined: Tue Feb 28, 2006 12:34 am

How to get Picture Sizes?

Post by Flipper3 »

Well, I am currently trying to modify my current BBCode tags, but I want to make the IMG tags to resize all pictures that are bigger than **** by **** pixels. However, I cannot figure out how to find the size of a picture from an external link. I can check pictures that are uploaded, but do not know how to check external ones. There must be a way, but HOW?!?

I have Googled and asked just about everywhere and no answer. So do you guys know how?


thetarget
Posts: 496
Joined: Sat Jul 09, 2005 9:10 am

Post by thetarget »

Flipper3
Posts: 353
Joined: Tue Feb 28, 2006 12:34 am

Post by Flipper3 »

That was the first thing that I tried, lol. But the problem with those is that it makes you upload. But I don't want to have the image uploaded.
Lixas
Posts: 750
Joined: Wed Feb 16, 2005 4:21 pm

Post by Lixas »

so you want to get image size without image uploaded to server ?
Image
thetarget
Posts: 496
Joined: Sat Jul 09, 2005 9:10 am

Post by thetarget »

getImageSize() needs image to be uploaded?
Lixas
Posts: 750
Joined: Wed Feb 16, 2005 4:21 pm

Post by Lixas »

function, that you just mentioned can be used for images, that are uploaded to server or for images, that can be reached via URL ( http://www.domain.com/images/picture.gif [need special server configuration] ) You can not use this function to get the size of images, that is on user computers. even javascript will not help you because of javascript's security restrtictions
Image
Flipper3
Posts: 353
Joined: Tue Feb 28, 2006 12:34 am

Post by Flipper3 »

Ok, so it grabs the image alright and all, but I cannot figure out how to get the size using: getimagesize(). PHP.net doesn't really help and no help found on Google either. Any help?.
Lixas
Posts: 750
Joined: Wed Feb 16, 2005 4:21 pm

Post by Lixas »

you need it size by bytes or size by dimensions? (width and height) ?
Image
Flipper3
Posts: 353
Joined: Tue Feb 28, 2006 12:34 am

Post by Flipper3 »

Lixas wrote:you need it size by bytes or size by dimensions? (width and height) ?
Dimensions and size, but dimensions are more important and what I really want.
Lixas
Posts: 750
Joined: Wed Feb 16, 2005 4:21 pm

Post by Lixas »

Flipper3 wrote:Dimensions and size, but dimensions are more important and what I really want.
[php]list($img_width, $img_height) = getimagesize("img/flag.jpg");[/php]and you will have variables $img_width, $img_height that you need.

To get a size by bytes use function filesize. Example:
[php]$img_size = filesize("img/flag.jpg");[/php] and you will have variable $img_size with images size by bytes. To convert bytes to normal look, you can use this function:

[php] function get_size($size)
{
$bytes = array('B','KB','MB','GB','TB');
foreach($bytes as $val) {
if($size > 1024){
$size = $size / 1024;
}else{
break;
}
}
return round($size, 2)." ".$val;
}[/php]if you need any more help regarding this topic, do not hesitate to ask
Image
Post Reply