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
https://forums.phpfreaks.com/topic/222202-php-noob-help-image-resize-on-the-fly/
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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.