Jump to content

need image resize function modified


simcoweb

Recommended Posts

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:

[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\"";

}

?>[/code]

Which uses this variable:

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

In order to get the current image size/dimensions.

Here's the HTML tag suggested:

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

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?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.