Jump to content

Image sizing


Schlo_50

Recommended Posts

You may want something like this


{
   $imgID = $row['st_id'];
   $imgSrc = $row['image'];
   $imgDesc = $row['descr'];
   $imgPrice = $row['price'];

   echo "$imgID. <img src=\"$imgSrc\" alt=\"$imgDesc - $imgPrice\" width=\"70\" height=\"70\" border=\"0\">\n";

}

 

 

Link to comment
https://forums.phpfreaks.com/topic/38892-image-sizing/#findComment-187029
Share on other sites

easy here you go

 

<?php

// Load image
$image = open_image('flower.jpg');//put thr correct varable here ok.
if ($image === false) { die ('Unable to open image'); }

// Get original width and height
$width = imagesx($image);
$height = imagesy($image);

// New width and height
$new_width = 150;
$new_height = 100;

// Resample
$image_resized = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

// Display resized image
header('Content-type: image/jpeg');
imagejpeg($image_resized);
die();

?>

Link to comment
https://forums.phpfreaks.com/topic/38892-image-sizing/#findComment-187038
Share on other sites

Sorry to be difficult but i'd prefer something to be implemented into what i already have:

 

mysql_connect ($host,$user,$pass) or die ( mysql_error ()); 
mysql_select_db ($db)or die ( mysql_error ()); 
$result = mysql_query ($show_all) or die ( mysql_error ()); 
while ($row = mysql_fetch_array ($result))
{
    echo $row['st_id']. ' - <img src="'. $row['image'] . '" />' . $row['descr'] . ' - ' . $row['price'] . "<br />\n";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/38892-image-sizing/#findComment-187039
Share on other sites

save this as resized_image.php

 


<?php

mysql_connect ($host,$user,$pass) or die ( mysql_error ()); 
mysql_select_db ($db)or die ( mysql_error ()); 
$result = mysql_query ($show_all) or die ( mysql_error ()); 
while ($row = mysql_fetch_array ($result))
{
$my_image=$row['image'];


// Load image
$image = open_image('$my_image');//put thr correct varable here ok.
if ($image === false) { die ('Unable to open image'); }

// Get original width and height
$width = imagesx($image);
$height = imagesy($image);

// New width and height
$new_width = 150;
$new_height = 100;

// Resample
$image_resized = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

// Display resized image
header('Content-type: image/jpeg');
imagejpeg($image_resized);
die();
}
?>

 

 

now point to it

 

mysql_connect ($host,$user,$pass) or die ( mysql_error ()); 
mysql_select_db ($db)or die ( mysql_error ()); 
$result = mysql_query ($show_all) or die ( mysql_error ()); 
while ($row = mysql_fetch_array ($result))
{
    echo $row['st_id']. ' - <img src='resize_image.php'>' . $row['descr'] . ' - ' . $row['price'] . "<br />\n";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/38892-image-sizing/#findComment-187046
Share on other sites

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.