Jump to content

PHP noob help! Image resize on the fly


nicedice

Recommended Posts

Hi All - I'm relatively new to php but i do have a small amount of understanding about it, so please no complicated jargon coz my head will bleed!

I have a php search getting specified info from a mysql db - when the data is returned it echo's out using this code:

$results=array();
$sql=$queryCriteria;
$result = mysql_query($sql,$link) or die('Error: ' . mysql_error()); 
while($a_row = mysql_fetch_array($result, MYSQL_ASSOC)) array_push($results, $a_row);

if(count($results)){
//DISPLAY THE DATA
foreach($results as $r){	
	echo('
	<div class="post cut alignleft">
            <div class="entry">
                <div class="double alignleft">
                    <a href="images/propertypics/'.$r['image_1'].'" rel="gallery">
				<img src="images/propertypics/'.$r['image_1'].'" alt="Pic" /></a>
                </div>
                
                <div class="sidebar alignright">
                    <h5>'.$r['address'].'</h5>
                    <p>'.$r['summary'].'</p>
				<h5>£'.$r['price'].' pm</h5>
                    <a class="morebutton moremd" href="property_lets.php?id='.$r['id'].'">More Info</a>
                </div>

            </div>
        </div>

	<br><br>');

}
}else{
echo('Sorry - no results found');
}

 

Now it works a treat but I need to add in an image resize function that exists on the website which uses this code:

<?php
$image = resize('your_image.jpg',array("w"=>600,"h"=>400));
?>
<img src="<?php echo $image; ?>" alt="Pic" />

 

I've tried various ways to shoehorn it in but with my limited php skills it's proving a pain.

Any help would be much appreciated!

Thanks in advance.

Link to comment
Share on other sites

Do you want the image physically changed in size or only changed in size for display purposes?

 

if it is just for display purposes you could hard code it like this

 

<img src="<?php echo $image; ?>" alt="Pic" width="600" />

 

it will auto scale the height to suit the image or you could set that aswell if you wanted to

Link to comment
Share on other sites

as an aside, if you are displaying images MANY times (the same one or different ones), that method while it will work for your visual purposes, results in increased load time as the the large image is being loaded, just displayed smaller. You might consider having a thumb version of your images to cut down on load times.

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.