Jump to content


Photo

image


  • Please log in to reply
8 replies to this topic

#1 corillo181

corillo181
  • Members
  • PipPipPip
  • Advanced Member
  • 896 posts

Posted 18 June 2006 - 02:55 PM

is there any way i can get the height and width of a image?

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 18 June 2006 - 02:58 PM

if it's already on your server - the getimagesize() function.
Legend has it that reading the manual never killed anyone.
My site

#3 corillo181

corillo181
  • Members
  • PipPipPip
  • Advanced Member
  • 896 posts

Posted 18 June 2006 - 03:19 PM

under wher ein php info would i find that?

cuz i tthink is if i had gd? and my server do

i try this but it does not work.
<?php 
function imageResize($width, $height, $target) { 
if ($width > $height) { 
$percentage = ($target / $width); 
} else { 
$percentage = ($target / $height); 
} 
$width = round($width * $percentage); 
$height = round($height * $percentage); 
return "width=\"$width\" height=\"$height\""; 
} 

include 'includes/db.php';
$query=mysql_query("SELECT path FROM tra_cotm_photo")or die("error: ".mysql_error());
$path=mysql_fetch_array($query);
$test = getimagesize("../cotm/457565197.jpg"); 
?>
<img src="../cotm/457565197.jpg" <?php imageResize($test[0],$test[1], 110); ?> />


#4 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 18 June 2006 - 03:33 PM

If you have the GD library installed, it's clearly visible in phpinfo (it has its own section of information).

If you have GD installed and your code "doesn't work", there something not right wih your code. What is (not) happening with that script that makes you think there's a problem?
Legend has it that reading the manual never killed anyone.
My site

#5 corillo181

corillo181
  • Members
  • PipPipPip
  • Advanced Member
  • 896 posts

Posted 18 June 2006 - 03:38 PM

tha tpage does nto resize with the function made.. so i think the imagesiz eit's not doign the work

and yes the gd is on..

plus i try using
<img src="image/123.jpg" atl="<?php getimagesize("image/123.jpg");?>">
to see if it would show me the image size but it doesn't..

#6 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 18 June 2006 - 05:00 PM

getimagesize returns an array of values. Try this:
$size = getimagesize("image/123.jpg");
echo "<img src='". image/123.jpg' ". $size[3]. ">";

Legend has it that reading the manual never killed anyone.
My site

#7 corillo181

corillo181
  • Members
  • PipPipPip
  • Advanced Member
  • 896 posts

Posted 18 June 2006 - 11:13 PM

mm that code is wrong and i dont see how tha tis going to tell me in any way if the #size is working.

#8 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 18 June 2006 - 11:22 PM

Sorry, try this:
$size = getimagesize("image/123.jpg");
echo "<img src='image/123.jpg' ". $size[3]. ">";
If GD is working and if image/123.jpg exists (it's your example, so I assume it would), then $size[3] will display the width and height of the image - exactly what it says in the php manual.
Legend has it that reading the manual never killed anyone.
My site

#9 corillo181

corillo181
  • Members
  • PipPipPip
  • Advanced Member
  • 896 posts

Posted 19 June 2006 - 01:01 PM

this worked..i got the hang of it.. thanx

$filename = 'images/123.jpg';
$size = getimagesize("images/123.jpg");
$width=$size[0];
$height=$size[1];
if($width >100 || $height >100){
$n_w=$width / 2;
$n_h=$height / 2;
echo '<img src="images/123.jpg" width="'.$n_w.'" height="'.$n_h.'" />';
}
?>







0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users