MP145 Posted October 22, 2008 Share Posted October 22, 2008 I am trying to display an image with a new height and width, but it's not working. Below is the code. ". $info['thumb'] ." will return the filename.jpg and the actual image is stored in "images/news" <?php mysql_connect("localhost", "xxx", "yyyy") or die(mysql_error()) ; mysql_select_db("news") or die(mysql_error()) ; //Retrieves data from MySQL $data = mysql_query("SELECT * FROM newsitem") or die(mysql_error()); //Puts it into an array while($info = mysql_fetch_array( $data )) { $size = getimagesize("images/news/". $info['thumb'] .""); $height = $size[1]; $width = $size[0]; if ($height > $width) { $height = 100; $percent = ($size[1] / $height); $width = ($size[0] / $percent); } else if ($width > $height) { $width = 100; $percent = ($size[0] / $width); $height = ($size[1] / $percent); } echo "<b><font face=\"Verdana\" size=\"2\" color=\"#000000\">News Title:</b> " . $info['title'] . "</font><br>"; echo "<b><font face=\"Verdana\" size=\"2\" color=\"#000000\">Posted By:</b> " .$info['addby'] . "</font><br>"; echo "<b><font face=\"Verdana\" size=\"2\" color=\"#000000\">Date Posted:</b> " .$info['date'] . "</font><br><br>"; echo "<b><font face=\"Verdana\" size=\"1\" color=\"#000000\"><a href=\"editnews.php?ID=" .$info['newsID']. "\">Edit News</a> | <a href=\"deletenews.php?ID=" .$info['newsID']. "\">Delete News</a></b></font><br>"; echo "<br><img src\"images/news/" . $info['thumb'] . "\" height=\"$height\" width=\"$width\" />"; echo "<hr>"; } ?> I can't see anything when the page is called. Please help. Thanks Link to comment https://forums.phpfreaks.com/topic/129648-solved-problem-on-image-resize/ Share on other sites More sharing options...
Maq Posted October 22, 2008 Share Posted October 22, 2008 Can you put this at the top of your script to make sure you're not receiving errors first: ini_set ("display_errors", "1"); error_reporting(E_ALL); Link to comment https://forums.phpfreaks.com/topic/129648-solved-problem-on-image-resize/#findComment-672139 Share on other sites More sharing options...
MP145 Posted October 22, 2008 Author Share Posted October 22, 2008 Thanks for the reply Maq It's working now. Also i missed = on the img src echo "<br><img src\"images/news/" . $info['thumb'] . "\" height=\"$height\" width=\"$width\" />"; should have been echo "<br><img src=\"images/news/" . $info['thumb'] . "\" height=\"$height\" width=\"$width\" />"; but now, images that are same in width and height is not resizing. How can i resize the image so that the height and width is 80 ? regardless the original size. Link to comment https://forums.phpfreaks.com/topic/129648-solved-problem-on-image-resize/#findComment-672156 Share on other sites More sharing options...
Maq Posted October 22, 2008 Share Posted October 22, 2008 Of course it's not working. It's because you have: if ($height > $width) AND else if ($width > $height) So what about =? You need to have a condition for this. Link to comment https://forums.phpfreaks.com/topic/129648-solved-problem-on-image-resize/#findComment-672159 Share on other sites More sharing options...
CroNiX Posted October 22, 2008 Share Posted October 22, 2008 or just an else (if its not the first 2 conditions, it will be equal) Link to comment https://forums.phpfreaks.com/topic/129648-solved-problem-on-image-resize/#findComment-672162 Share on other sites More sharing options...
Maq Posted October 22, 2008 Share Posted October 22, 2008 Add: else { $height = 80; $width = 80; } Link to comment https://forums.phpfreaks.com/topic/129648-solved-problem-on-image-resize/#findComment-672166 Share on other sites More sharing options...
MP145 Posted October 22, 2008 Author Share Posted October 22, 2008 Thanks guys. I just changed it to :- <?php $maxheight = 80; $maxwidth = 80; if ($height > $maxheight) { $height = 80; } if ($width > $maxwidth) { $width = 80; } ?> Link to comment https://forums.phpfreaks.com/topic/129648-solved-problem-on-image-resize/#findComment-672214 Share on other sites More sharing options...
DarkWater Posted October 22, 2008 Share Posted October 22, 2008 You should use: <?php $maxheight = 80; $maxwidth = 80; if ($height > $maxheight) { $height = $maxheight; } if ($width > $maxwidth) { $width = $maxwidth; } ?> Incase you change it to something other than 80. Link to comment https://forums.phpfreaks.com/topic/129648-solved-problem-on-image-resize/#findComment-672216 Share on other sites More sharing options...
MP145 Posted October 22, 2008 Author Share Posted October 22, 2008 Done. Thanks DarkWater Link to comment https://forums.phpfreaks.com/topic/129648-solved-problem-on-image-resize/#findComment-672223 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.