Schlo_50 Posted February 17, 2007 Share Posted February 17, 2007 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 Quote Link to comment Share on other sites More sharing options...
hvle Posted February 17, 2007 Share Posted February 17, 2007 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"; } Quote Link to comment Share on other sites More sharing options...
Schlo_50 Posted February 17, 2007 Author Share Posted February 17, 2007 I just used that but my prices and descriptions aren't displaying now. Quote Link to comment Share on other sites More sharing options...
redarrow Posted February 17, 2007 Share Posted February 17, 2007 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(); ?> Quote Link to comment Share on other sites More sharing options...
Schlo_50 Posted February 17, 2007 Author Share Posted February 17, 2007 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"; } ?> Quote Link to comment Share on other sites More sharing options...
redarrow Posted February 17, 2007 Share Posted February 17, 2007 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"; } ?> Quote Link to comment Share on other sites More sharing options...
hvle Posted February 17, 2007 Share Posted February 17, 2007 I just used that but my prices and descriptions aren't displaying now. well then you are going the right way, keep working on it. Quote Link to comment Share on other sites More sharing options...
Schlo_50 Posted February 17, 2007 Author Share Posted February 17, 2007 No error is generated they just won't display.. Quote Link to comment Share on other sites More sharing options...
hvle Posted February 17, 2007 Share Posted February 17, 2007 can you post an example row which retrieved from database? Quote Link to comment Share on other sites More sharing options...
Schlo_50 Posted February 17, 2007 Author Share Posted February 17, 2007 I think thats what you requested. http://img187.imageshack.us/img187/5981/untitledtb0.jpg Quote Link to comment Share on other sites More sharing options...
hvle Posted February 17, 2007 Share Posted February 17, 2007 good, you posted the table structure. Could you also post a sample row, a typical row with data which retrieved from database? Quote Link to comment Share on other sites More sharing options...
Schlo_50 Posted February 17, 2007 Author Share Posted February 17, 2007 This? http://img187.imageshack.us/img187/2315/untitled1ez7.jpg Quote Link to comment Share on other sites More sharing options...
hvle Posted February 17, 2007 Share Posted February 17, 2007 try something like this: { $imgID = $row['st_id']; $imgSrc = $row['image']; echo "<img src=\"$imgSrc\" width=\"70\" height=\"70\" border=\"0\">\n"; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.