sargosis Posted April 4, 2008 Share Posted April 4, 2008 I am having trouble trying to resize my images on my gallery. I had a method that worked previously, however an unfortunate formatting had me reinstalling Apache and i'm still finding i have to fiddle with the settings from time to time. Previously, to resize an image, i would use a piece of code in the link like what follows: $link = "imageresize.php?file=some.jpg&width=100&height=100"; echo "<img src=".$link.">"; This link called upon another PHP file named imageresize.php that i wrote to handle the actual resizing (shown below): <?php $filename = urldecode($_GET['file']); // Content type header('Content-type: image/jpeg'); // Get sizes $width = $_GET['width']; $height = $_GET['height']; list($width_orig, $height_orig) = getimagesize($filename); // Load $thumb = imagecreatetruecolor($width, $height); $source = imagecreatefromjpeg($filename); // Resize imagecopyresized($thumb, $source, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); // Output imagejpeg($thumb, '', 100); ?> The problem is, for some reason, now imageresize.php either isn't called or doesn't respond. I've tried getting rid of any .htaccess files to prevent permission problems, but the file still doesn't respond. Does anyone have any ideas or suggestions i could do to get this working again? ??? Link to comment https://forums.phpfreaks.com/topic/99594-help-pleaseimage-resizing-and-file-calling-problems/ Share on other sites More sharing options...
craygo Posted April 4, 2008 Share Posted April 4, 2008 I made a function similar to what you have accept it will handle jpg, gif, png. It works the same way as your does except you just use a max size. that way the aspect ratio is retained. <?php /********************************** * Will resize an image to a * * max width or height and keep * * aspect ratio Name this file * * anything you like. * * I will use imageresize.php * **********************************/ header('Content-type: image/jpeg'); function resampleimage($maxsize, $sourcefile, $imgcomp=0) { $g_imgcomp=100-$imgcomp; if(file_exists($sourcefile)) { $g_is=getimagesize($sourcefile); if($g_is[0] <= $maxsize && $g_is[1] <= $maxsize){ $new_width=$g_is[0]; $new_height=$g_is[1]; } else { $w_adjust = ($maxsize / $g_is[0]); $h_adjust = ($maxsize / $g_is[1]); if($w_adjust <= $h_adjust) { $new_width=($g_is[0]*$w_adjust); $new_height=($g_is[1]*$w_adjust); } else { $new_width=($g_is[0]*$h_adjust); $new_height=($g_is[1]*$h_adjust); } } //SEARCHES IMAGE NAME STRING TO SELECT EXTENSION (EVERYTHING AFTER . ) $image_type = strrchr($sourcefile, "."); //SWITCHES THE IMAGE CREATE FUNCTION BASED ON FILE EXTENSION switch($image_type) { case '.jpg': $img_src = imagecreatefromjpeg($sourcefile); break; case '.png': $img_src = imagecreatefrompng($sourcefile); break; case '.gif': $img_src = imagecreatefromgif($sourcefile); break; default: echo("Error Invalid Image Type"); die; break; } $img_dst=imagecreatetruecolor($new_width,$new_height); imagecopyresampled($img_dst, $img_src, 0, 0, 0, 0, $new_width, $new_height, $g_is[0], $g_is[1]); imagejpeg($img_dst); imagedestroy($img_dst); imagedestroy($img_src); return true; } else return false; } // now call the image from any other page with <img src="imageresize.php?maxsize=xxx&source=path/to/image/file" border=0 /> resampleimage($_GET['maxsize'], $_GET['source']); ?> I have had no issues with it. Ray Link to comment https://forums.phpfreaks.com/topic/99594-help-pleaseimage-resizing-and-file-calling-problems/#findComment-509524 Share on other sites More sharing options...
sargosis Posted April 4, 2008 Author Share Posted April 4, 2008 Thank you for the quick reply and the example script, but my question's focus is more on the utilization of it. Notably, how do you call upon it and did you have to fiddle with any apache settings to get that to work? Here's how i called the php file: $link = "imageresize.php?file=some.jpg&width=100&height=100"; echo "<img src=".$link.">"; Link to comment https://forums.phpfreaks.com/topic/99594-help-pleaseimage-resizing-and-file-calling-problems/#findComment-509531 Share on other sites More sharing options...
craygo Posted April 4, 2008 Share Posted April 4, 2008 the way you call it the file has to be in the same directory as the script that is running. if "some.jpg" is in a folder called images then it should be file=images/some.jpg. also imageresize has to be in the same folder as your script. Link to comment https://forums.phpfreaks.com/topic/99594-help-pleaseimage-resizing-and-file-calling-problems/#findComment-509539 Share on other sites More sharing options...
craygo Posted April 4, 2008 Share Posted April 4, 2008 I copy and pasted your code and it works fine by using <img src="imresize.php?width=500&height=500&file=images/AMG E55.jpg" border=0 /> So not sure if it's your setup Ray Link to comment https://forums.phpfreaks.com/topic/99594-help-pleaseimage-resizing-and-file-calling-problems/#findComment-509546 Share on other sites More sharing options...
sargosis Posted April 4, 2008 Author Share Posted April 4, 2008 Everything's in the same folder for simplicity's sake. However, that hasn't fixed the issue :-\ If it is the setup, like i feared, is there anything that might make the php file not respond? Link to comment https://forums.phpfreaks.com/topic/99594-help-pleaseimage-resizing-and-file-calling-problems/#findComment-509547 Share on other sites More sharing options...
craygo Posted April 4, 2008 Share Posted April 4, 2008 Sorry I am using IIS here. I am not really an apache guy. Hopefully someone can help out cause as far as my web server goes, your code works fine. also did you install php5. People are saying they are having alot of problem with using short tags in their scripts. check and make sure you are using proper tags and syntax like: <?php and not <? <?php echo $something; ?> and not <?=$something?> Check it out Ray Link to comment https://forums.phpfreaks.com/topic/99594-help-pleaseimage-resizing-and-file-calling-problems/#findComment-509553 Share on other sites More sharing options...
sargosis Posted April 4, 2008 Author Share Posted April 4, 2008 I changed the code to get rid of the short tags like you suggested and i am using php5. Unfortunately, the script still does not work. Does anyone have any experience with apache? i'm thinking it might be a permissions issue, despite my getting rid of the .htaccess files that caused the restriction. Link to comment https://forums.phpfreaks.com/topic/99594-help-pleaseimage-resizing-and-file-calling-problems/#findComment-509559 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.