ROCKINDANO Posted December 10, 2009 Share Posted December 10, 2009 Can someone tell me why this isn't working? i am trying to resize an image that gets uploaded to a dir. and db stores the file name under the "file" column. this is the page that displays the image : print '<img src="images/resize_image.php?file=$pic" title="" border="0" width="170" height="135" class="floatright" style="margin-left: 5px; border: 2px solid #CCCCCC; padding: 3px; background: #9bbdfd;" />'; this is the page that resizes the images: <?php $pic = $HTTP_GET_VARS['file']; print $pic; print "image "; if (!max_width) $max_width = 80; if (!max_height) $max_height = 60; $size = GetpicSize($pic); $width = $size[0]; $height = $size[1]; $x_ratio = $max_width / $width; $y_ratio = $max_height / $height; if ( ($width <= $max_width) && ($height <= $max_height) ) { $tn_width = $width; $tn_height = $height; } else if (($x_ratio * $height) < $max_height) { $tn_height = ceil($x_ratio * $height); $tn_widht = $max_width; } else { $tn_width = ceil($y_ratio * $width); $tn_height = $max_height; } $src = ImageCreateFromJpeg($pic); $dst = ImageCreate($tn_width, $tn_height); ImageCopyResize($dt, $src, 0,0,0,0, $tn_width, $tn_height, $width,$height); header('Content-type: image/jpeg'); ImageJpeg($dst, null, -1); ImageDestroy($src); ImageDestroy($dst); ?> Quote Link to comment https://forums.phpfreaks.com/topic/184649-resizing-images-from-db/ Share on other sites More sharing options...
Buddski Posted December 10, 2009 Share Posted December 10, 2009 2 things I have noticed. 1. if (!max_width) $max_width = 80; if (!max_height) $max_height = 60; should be if (!isset($max_width)) $max_width = 80; if (!isset($max_height)) $max_height = 60; and secondly remove the print calls on the top section of the script. Quote Link to comment https://forums.phpfreaks.com/topic/184649-resizing-images-from-db/#findComment-974833 Share on other sites More sharing options...
ROCKINDANO Posted December 10, 2009 Author Share Posted December 10, 2009 well that still didn't work. for some reason its not passing the image file name to the script Quote Link to comment https://forums.phpfreaks.com/topic/184649-resizing-images-from-db/#findComment-974839 Share on other sites More sharing options...
Buddski Posted December 10, 2009 Share Posted December 10, 2009 Ok. without seeing the main page and where the file name is coming from I cant give any more insight but I did notice 1 other thing that I believe is your main issue.. print '<img src="images/resize_image.php?file=$pic" title="" border="0" width="170" height="135" class="floatright" style="margin-left: 5px; border: 2px solid #CCCCCC; padding: 3px; background: #9bbdfd;" />'; should be print '<img src="images/resize_image.php?file='.$pic.'" title="" border="0" width="170" height="135" class="floatright" style="margin-left: 5px; border: 2px solid #CCCCCC; padding: 3px; background: #9bbdfd;" />'; You cant include variables into a string using single quotes.. Quote Link to comment https://forums.phpfreaks.com/topic/184649-resizing-images-from-db/#findComment-974846 Share on other sites More sharing options...
premiso Posted December 10, 2009 Share Posted December 10, 2009 $HTTP_GET_VARS has long been depreciated. Use $_GET instead. (Not that it will fix it, just a side note.) Quote Link to comment https://forums.phpfreaks.com/topic/184649-resizing-images-from-db/#findComment-974849 Share on other sites More sharing options...
ROCKINDANO Posted December 10, 2009 Author Share Posted December 10, 2009 here is my main page <?php if(!($db = @ mysql_connect('localhost', 'user', 'pass'))) { print "Error: Could not connect to our database sorry for any inconvenience.<br /> Please try at a later time."; } //select which database you want to edit mysql_select_db("db"); // $news_id=mysql_real_escape_string($_GET[news_id]); $query = "SELECT * FROM news ORDER BY news_id DESC LIMIT 6"; $result = mysql_query($query); ?> <div style="background:#cfdbea; height:180px;padding: 5px; font-size: 14px"> <div style="background:#FFFFFF; height:160px; padding:10px;"> <?php $i = 1; while ($r=mysql_fetch_array($result)) { $news_id=$r["news_id"]; $title=$r["title"]; $fulldesc=$r["fulldesc"]; $pic=$r["file"]; ?> <div id="slide<?php print $i; ?>" class='slides'> <div class='slideTitle' style="padding-bottom:2px;"> <?php if ($pic!="") { print "<img src=\"images/resize_image.php?file = '.$pic.'\" border=\"1\" class=\"floatright\" title=\".$pic.\" alt=\"$pic\" />"; // print '<img src="images/'.$pic.'" title="" border="0" width="170" height="135" class="floatright" style="margin-left: 5px; border: 2px solid #CCCCCC; padding: 3px; background: #9bbdfd;" />'; } else print '<img src="images/imageholdershow.jpg" title="" border="2" width="170" height="135" class="floatright" style="margin-left: 5px; border: 2px solid #CCCCCC; padding: 3px; background: #9bbdfd;" />'; ?> <?php print "<p style='padding: 0px;'><a href='newsevents.php?news_id={$news_id}' style='color:#9F0000; text-decoration:underline'>".$title."</a>"; ?></div> <p><?php print substr($fulldesc = $r["fulldesc"], 0, 280); print "… <a href='newsevents.php?news_id={$news_id}' style=\"font-size: 11px\">Full Story »</a></p>"; ?> </div> <?php $i++; }//end while loop ?> Quote Link to comment https://forums.phpfreaks.com/topic/184649-resizing-images-from-db/#findComment-974850 Share on other sites More sharing options...
Buddski Posted December 10, 2009 Share Posted December 10, 2009 Your image tag has to be either: print "<img src=\"images/resize_image.php?file=$pic\" border=\"1\" class=\"floatright\" title=\".$pic.\" alt=\"$pic\" />"; -- OR -- print '<img src="images/'.$pic.'" title="" border="0" width="170" height="135" class="floatright" style="margin-left: 5px; border: 2px solid #CCCCCC; padding: 3px; background: #9bbdfd;" />'; Double quotes allow you to have variables in them single quoted strings do not.. eg: $name = 'Buddski'; echo "Hello, $name, how are you?"; //would output 'Hello, Buddski, how are you?' echo 'Hello, $name'; // would output 'Hello, $name, how are you?' echo 'Hello, '.$name.' how are you?'; // would output 'Hello, Buddski, how are you?' Quote Link to comment https://forums.phpfreaks.com/topic/184649-resizing-images-from-db/#findComment-974860 Share on other sites More sharing options...
ROCKINDANO Posted December 10, 2009 Author Share Posted December 10, 2009 ok i changed it to print "<img src=\"images/resize_image.php?file=.$pic.\" border=\"1\" class=\"floatright\" title=\".$pic.\" alt=\"$pic\" />"; Quote Link to comment https://forums.phpfreaks.com/topic/184649-resizing-images-from-db/#findComment-974862 Share on other sites More sharing options...
Buddski Posted December 10, 2009 Share Posted December 10, 2009 remove the full stops on either side of the $pic variable.. so it is just plain file=$pic Quote Link to comment https://forums.phpfreaks.com/topic/184649-resizing-images-from-db/#findComment-974863 Share on other sites More sharing options...
ROCKINDANO Posted December 10, 2009 Author Share Posted December 10, 2009 still no image. i am quessing that the re size script is not getting the file name Quote Link to comment https://forums.phpfreaks.com/topic/184649-resizing-images-from-db/#findComment-974866 Share on other sites More sharing options...
Buddski Posted December 10, 2009 Share Posted December 10, 2009 view the output source code in your browser.. that will tell you the image path for the image tag.. Quote Link to comment https://forums.phpfreaks.com/topic/184649-resizing-images-from-db/#findComment-974867 Share on other sites More sharing options...
ROCKINDANO Posted December 10, 2009 Author Share Posted December 10, 2009 what do you mean? Quote Link to comment https://forums.phpfreaks.com/topic/184649-resizing-images-from-db/#findComment-974868 Share on other sites More sharing options...
Buddski Posted December 10, 2009 Share Posted December 10, 2009 After you have executed your script in the browser view the source code.. the page where no image shows up.. Navigate your way through it and find the image tag.. and read it src value.. Alternativley you can right click where the image is supposed to be (depending on your browser) and view the properties of the image which will also give you its src value.. Quote Link to comment https://forums.phpfreaks.com/topic/184649-resizing-images-from-db/#findComment-974873 Share on other sites More sharing options...
ROCKINDANO Posted December 10, 2009 Author Share Posted December 10, 2009 it gets the image because it gives me the name of the file. and this is what the source code shows as the image tag path: <img src="images/resize_image.php?file=forbeslogo.jpg" border="1" class="floatright" title="forbeslogo.jpg" alt="forbeslogo.jpg" /> and the title and alt attributes in the img tag show the name of the file. but don't know why it is not showing. Quote Link to comment https://forums.phpfreaks.com/topic/184649-resizing-images-from-db/#findComment-974875 Share on other sites More sharing options...
Buddski Posted December 10, 2009 Share Posted December 10, 2009 Now we know that the issue lies within the resizing script and your main page is working correctly.. The best way to see whats going on in the resize script is to goto it in your browser, doing this may show you any errors the script has.. Quote Link to comment https://forums.phpfreaks.com/topic/184649-resizing-images-from-db/#findComment-974882 Share on other sites More sharing options...
ROCKINDANO Posted December 10, 2009 Author Share Posted December 10, 2009 i'm sorry but how would i do that? Quote Link to comment https://forums.phpfreaks.com/topic/184649-resizing-images-from-db/#findComment-974887 Share on other sites More sharing options...
ROCKINDANO Posted December 10, 2009 Author Share Posted December 10, 2009 How would i do that? Quote Link to comment https://forums.phpfreaks.com/topic/184649-resizing-images-from-db/#findComment-974888 Share on other sites More sharing options...
ROCKINDANO Posted December 10, 2009 Author Share Posted December 10, 2009 oh k i think i know whats wrong. would it be the location of the script (the directory where stored) and the location of the image file? Quote Link to comment https://forums.phpfreaks.com/topic/184649-resizing-images-from-db/#findComment-974893 Share on other sites More sharing options...
mikesta707 Posted December 10, 2009 Share Posted December 10, 2009 Usually the way you go to a script is to browse to its location on the server... Quote Link to comment https://forums.phpfreaks.com/topic/184649-resizing-images-from-db/#findComment-974898 Share on other sites More sharing options...
Buddski Posted December 10, 2009 Share Posted December 10, 2009 if the resizing script is in the same directory as the file you are passing to it it should work.. Are you seeing any errors on the script when you enter it into your browser? for the sake of it. change ImageJpeg($dst, null, -1); to imagejpeg($dst); Also I noticed another issue ImageCopyResize($dt, $src, 0,0,0,0, $tn_width, $tn_height, $width,$height); should be imagecopyresized($dst, $src, 0,0,0,0, $tn_width, $tn_height, $width,$height); We will get there Quote Link to comment https://forums.phpfreaks.com/topic/184649-resizing-images-from-db/#findComment-974901 Share on other sites More sharing options...
ROCKINDANO Posted December 10, 2009 Author Share Posted December 10, 2009 well i can't seem to find the problem. the script gets everything from the file name to size etc... but can't display it to the browser. Quote Link to comment https://forums.phpfreaks.com/topic/184649-resizing-images-from-db/#findComment-974910 Share on other sites More sharing options...
Buddski Posted December 10, 2009 Share Posted December 10, 2009 Can you email me the resizing script and ill get it working for you.. send it to buddski@hotmail.com and ill have it back to you in a jiffy.. Quote Link to comment https://forums.phpfreaks.com/topic/184649-resizing-images-from-db/#findComment-974914 Share on other sites More sharing options...
ROCKINDANO Posted December 10, 2009 Author Share Posted December 10, 2009 can you get it from the attachment? [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/184649-resizing-images-from-db/#findComment-974919 Share on other sites More sharing options...
Buddski Posted December 10, 2009 Share Posted December 10, 2009 Remove line 4 and line 36.. You cannot have ANY output from the script otherwise it kills the image.. by removing those 2 prints your code works perfectly.. Quote Link to comment https://forums.phpfreaks.com/topic/184649-resizing-images-from-db/#findComment-974926 Share on other sites More sharing options...
ROCKINDANO Posted December 10, 2009 Author Share Posted December 10, 2009 so why doesn't it show the image? if i browse through my main code and see the img tag and click on it it takes me to a page that has file not found. Quote Link to comment https://forums.phpfreaks.com/topic/184649-resizing-images-from-db/#findComment-974927 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.