Jump to content


Photo

need image resize function modified


  • Please log in to reply
2 replies to this topic

#1 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 03 October 2006 - 05:14 PM

I have a page displaying member profiles along with a photo of each. I'd like the photos to be able to be displayed in various sizes throughout the site but don't want to create multiple images of each to do so. I have this function that resizes but the method it's using is by actually naming the image you want resized. Instead I want it to extract the image name from the database then display the resized image in the page where I have the <img src tag. Here's the function code:

<?php

function imageResize($width, $height, $target) {

//takes the larger size of the width and height and applies the  
formula accordingly...this is so this script will work  
dynamically with any size image

if ($width > $height) {
$percentage = ($target / $width);
} else {
$percentage = ($target / $height);
}

//gets the new value and applies the percentage, then rounds the value
$width = round($width * $percentage);
$height = round($height * $percentage);

//returns the new sizes in html image tag format...this is so you
can plug this function inside an image tag and just get the

return "width=\"$width\" height=\"$height\"";

}

?>

Which uses this variable:

$myphoto = getimagesize("images/photo/imagename001.jpg");

In order to get the current image size/dimensions.

Here's the HTML tag suggested:

<img src="images/photo/image001.jpg" <?php imageResize($myphoto[0], $myphoto[1], 150); ?>

My problem is that the name of the image is not known. Therefore I can't set that $myphoto variable. In my case the name of the image needs to come from a mysql query which returns the information from a field labeled 'photo'. The page will display several profiles per page. Therefore the image needs to be relevant to the profiles being shown. Right now the profiles are fine as far as displaying them in the proper order, etc. The only issue is the image resizing per image displayed.

Help?

#2 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 03 October 2006 - 09:44 PM

*little bump* :)

#3 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 04 October 2006 - 03:51 PM

Anyone?  :(




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users