Page 1 of 2

How to get Picture Sizes?

Posted: Sun Mar 02, 2008 5:52 pm
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?

Posted: Tue Mar 04, 2008 8:28 am
by thetarget

Posted: Tue Mar 04, 2008 10:34 pm
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.

Posted: Tue Mar 04, 2008 10:44 pm
by Lixas
so you want to get image size without image uploaded to server ?

Posted: Wed Mar 05, 2008 9:23 pm
by thetarget
getImageSize() needs image to be uploaded?

Posted: Wed Mar 05, 2008 10:07 pm
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

Posted: Sat Mar 15, 2008 7:13 pm
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?.

Posted: Wed Mar 19, 2008 8:41 am
by Lixas
you need it size by bytes or size by dimensions? (width and height) ?

Posted: Wed Mar 19, 2008 9:14 pm
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.

Posted: Thu Mar 20, 2008 8:07 am
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