Jump to content

Image sizing


Schlo_50

Recommended Posts

What can i add to this piece of code to make the image i am retrieving from my database downcale itself to appear 75 pixels by 75 pixels?

 

{
    echo $row['st_id']. ' - <img src="'. $row['image'] . '" />' . $row['descr'] . ' - ' . $row['price'] . "<br />\n";
}

 

Thanks in advance PHP'ers

Link to comment
Share on other sites

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