The Little Guy Posted March 25, 2007 Share Posted March 25, 2007 Anyone know why this isn't working? I can not figure it out. It was working at one point, I don't think I did anything to it, and now it doesn't work. When I do This on my page, All it does is print the alt text. <img alt="image" src="resize.php?image_id=<?php echo $_GET['image_id'];?>&percent=<?php echo $_GET['percent']; ?>"> Resize.php: <?php // The file session_start(); $img_id = $_GET['image_id']; include"db.php"; $img = mysql_query("SELECT * FROM files where file_id='$img_id'")or die(mysql_error()); $imgs = mysql_fetch_array($img); $filename = "users/".$_SESSION['user']."/".$imgs['file_name']; $percent = $_GET['percent']; switch($percent){ case ".25"; $percent = .25; break; case ".50"; $percent = .50; break; case ".75"; $percent = .75; break; case "1"; $percent = 1; break; default: $size = GetImageSize($filename); $width = $size[0]; if($width < 200){ $percent = 1; }else{ $percent = .5; } break; } // Content type if(getext($filename)=='.jpg'){ header('Content-type: image/jpeg'); }elseif(getext($filename)=='.gif'){ header('Content-type: image/gif'); }elseif(getext($filename)=='.png'){ header('Content-type: image/png'); } // Get new sizes list($width, $height) = getimagesize($filename); $newwidth = $width * $percent; $newheight = $height * $percent; // Load $thumb = imagecreatetruecolor($newwidth, $newheight); if(getext($filename)=='.jpg'){ $source = imagecreatefromjpeg($filename); }elseif(getext($filename)=='.gif'){ $source = imagecreatefromgif($filename); }elseif(getext($filename)=='.png'){ $source = imagecreatefrompng($filename); $alpha = imagealphablending($source, true); imagesavealpha($alpha, true); } // Resize imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); // Output if(getext($filename)=='.jpg'){ imagejpeg($thumb); }elseif(getext($filename)=='.gif'){ imagegif($thumb); }elseif(getext($filename)=='.png'){ imagepng($thumb); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/44189-image-resize-on-the-fly/ Share on other sites More sharing options...
MadTechie Posted March 25, 2007 Share Posted March 25, 2007 Whats $filename returning? <?php $filename = "users/".$_SESSION['user']."/".$imgs['file_name']; echo $filename; //<--Add die; //<--Add ?> Quote Link to comment https://forums.phpfreaks.com/topic/44189-image-resize-on-the-fly/#findComment-214605 Share on other sites More sharing options...
The Little Guy Posted March 25, 2007 Author Share Posted March 25, 2007 One example (It is the correct file path): users/ryan/07.jpg Quote Link to comment https://forums.phpfreaks.com/topic/44189-image-resize-on-the-fly/#findComment-214613 Share on other sites More sharing options...
MadTechie Posted March 25, 2007 Share Posted March 25, 2007 changing the <?php $filename = "users/".$_SESSION['user']."/".$imgs['file_name']; ?> so is the full path to the image or even add a $filename below it with a full known path just to force it to a image. Quote Link to comment https://forums.phpfreaks.com/topic/44189-image-resize-on-the-fly/#findComment-214614 Share on other sites More sharing options...
The Little Guy Posted March 25, 2007 Author Share Posted March 25, 2007 I have tried, and I get this result (Same result as before): http://tzfiles.com/resize.php?image_id=165&percent=1 Quote Link to comment https://forums.phpfreaks.com/topic/44189-image-resize-on-the-fly/#findComment-214618 Share on other sites More sharing options...
MadTechie Posted March 25, 2007 Share Posted March 25, 2007 ok well i think you have a GD problem, try <?php // Load $thumb = @imagecreatetruecolor($newwidth, $newheight) or die("Cannot Initialize new GD image stream") //<---changed ?> do a phpinfo(); and check it Quote Link to comment https://forums.phpfreaks.com/topic/44189-image-resize-on-the-fly/#findComment-214622 Share on other sites More sharing options...
The Little Guy Posted March 25, 2007 Author Share Posted March 25, 2007 My PHP info: http://tzfiles.com/info.php Quote Link to comment https://forums.phpfreaks.com/topic/44189-image-resize-on-the-fly/#findComment-214624 Share on other sites More sharing options...
MadTechie Posted March 25, 2007 Share Posted March 25, 2007 Hummmmmm OK hate me but still please try this add this <?php function getext() { return ".jpg"; } ?> and test a jpg file from my server (linking to yours without the database of course) http://www.madtechiesupport.com/test3.php?user=ryan&image_id=img_23&percent=.75 Quote Link to comment https://forums.phpfreaks.com/topic/44189-image-resize-on-the-fly/#findComment-214627 Share on other sites More sharing options...
The Little Guy Posted March 25, 2007 Author Share Posted March 25, 2007 If I add that, it just says that that function has already been declared (Declared in db.php) I am also not exactly sure what you want me to do. Quote Link to comment https://forums.phpfreaks.com/topic/44189-image-resize-on-the-fly/#findComment-214649 Share on other sites More sharing options...
MadTechie Posted March 25, 2007 Share Posted March 25, 2007 ok you have a problem in the db.php then, only works with jpg's but its only a test as well.. here's my link www.madtechiesupport.com/test3.php?user=ryan&image_id=img_23&percent=.75 heres the code <?php function getext() { return ".jpg"; } // The file session_start(); $img_id = $_GET['image_id']; $user = $_GET['user']; /*include"db.php"; $img = mysql_query("SELECT * FROM files where file_id='$img_id'")or die(mysql_error()); $imgs = mysql_fetch_array($img); $filename = "users/".$_SESSION['user']."/".$imgs['file_name'];*/ $filename = "http://tzfiles.com/users/$user/$img_id.jpg"; $percent = $_GET['percent']; switch($percent){ case ".25"; $percent = .25; break; case ".50"; $percent = .50; break; case ".75"; $percent = .75; break; case "1"; $percent = 1; break; default: $size = GetImageSize($filename); $width = $size[0]; if($width < 200){ $percent = 1; }else{ $percent = .5; } break; } // Content type if(getext($filename)=='.jpg'){ header('Content-type: image/jpeg'); }elseif(getext($filename)=='.gif'){ header('Content-type: image/gif'); }elseif(getext($filename)=='.png'){ header('Content-type: image/png'); } // Get new sizes list($width, $height) = getimagesize($filename); $newwidth = $width * $percent; $newheight = $height * $percent; // Load $thumb = imagecreatetruecolor($newwidth, $newheight); if(getext($filename)=='.jpg'){ $source = imagecreatefromjpeg($filename); }elseif(getext($filename)=='.gif'){ $source = imagecreatefromgif($filename); }elseif(getext($filename)=='.png'){ $source = imagecreatefrompng($filename); $alpha = imagealphablending($source, true); imagesavealpha($alpha, true); } // Resize imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); // Output if(getext($filename)=='.jpg'){ imagejpeg($thumb); }elseif(getext($filename)=='.gif'){ imagegif($thumb); }elseif(getext($filename)=='.png'){ imagepng($thumb); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/44189-image-resize-on-the-fly/#findComment-214650 Share on other sites More sharing options...
The Little Guy Posted March 25, 2007 Author Share Posted March 25, 2007 that didn't work... I realized that If I view the source, I get this: <br /> <b>Warning</b>: getimagesize() [<a href='function.getimagesize'>function.getimagesize</a>]: URL file-access is disabled in the server configuration in <b>/home/.marble/ryannaddy/tzfiles.com/resize.php</b> on line <b>52</b><br /> <br /> <b>Warning</b>: getimagesize(http://tzfiles.com/users/ryan/img_23.jpg) [<a href='function.getimagesize'>function.getimagesize</a>]: failed to open stream: no suitable wrapper could be found in <b>/home/.marble/ryannaddy/tzfiles.com/resize.php</b> on line <b>52</b><br /> <br /> <b>Warning</b>: imagecreatetruecolor() [<a href='function.imagecreatetruecolor'>function.imagecreatetruecolor</a>]: Invalid image dimensions in <b>/home/.marble/ryannaddy/tzfiles.com/resize.php</b> on line <b>57</b><br /> <br /> <b>Warning</b>: imagecreatefromjpeg() [<a href='function.imagecreatefromjpeg'>function.imagecreatefromjpeg</a>]: URL file-access is disabled in the server configuration in <b>/home/.marble/ryannaddy/tzfiles.com/resize.php</b> on line <b>60</b><br /> <br /> <b>Warning</b>: imagecreatefromjpeg(http://tzfiles.com/users/ryan/img_23.jpg) [<a href='function.imagecreatefromjpeg'>function.imagecreatefromjpeg</a>]: failed to open stream: no suitable wrapper could be found in <b>/home/.marble/ryannaddy/tzfiles.com/resize.php</b> on line <b>60</b><br /> <br /> <b>Warning</b>: imagecopyresized(): supplied argument is not a valid Image resource in <b>/home/.marble/ryannaddy/tzfiles.com/resize.php</b> on line <b>69</b><br /> <br /> <b>Warning</b>: imagejpeg(): supplied argument is not a valid Image resource in <b>/home/.marble/ryannaddy/tzfiles.com/resize.php</b> on line <b>73</b><br /> Quote Link to comment https://forums.phpfreaks.com/topic/44189-image-resize-on-the-fly/#findComment-214662 Share on other sites More sharing options...
MadTechie Posted March 25, 2007 Share Posted March 25, 2007 change the $filename = "http://tzfiles.com/users/$user/$img_id.jpg"; to $filename = "users/$user/$img_id.jpg"; for your one i needed the "http://tzfiles.com/" as its running from my server. Quote Link to comment https://forums.phpfreaks.com/topic/44189-image-resize-on-the-fly/#findComment-214667 Share on other sites More sharing options...
The Little Guy Posted March 25, 2007 Author Share Posted March 25, 2007 by changing $filename to this: $filename = "users/$user/$img_id.jpg"; Made it work. Quote Link to comment https://forums.phpfreaks.com/topic/44189-image-resize-on-the-fly/#findComment-214668 Share on other sites More sharing options...
The Little Guy Posted March 25, 2007 Author Share Posted March 25, 2007 Umm..... OK.... I didn't change any code, and now the original code works... WTF? Quote Link to comment https://forums.phpfreaks.com/topic/44189-image-resize-on-the-fly/#findComment-214669 Share on other sites More sharing options...
MadTechie Posted March 25, 2007 Share Posted March 25, 2007 Erm.. Well Done.. i think lol ??? Quote Link to comment https://forums.phpfreaks.com/topic/44189-image-resize-on-the-fly/#findComment-214671 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.