lucan Posted April 27, 2011 Share Posted April 27, 2011 I have a script that uploads my images to a folder and database which works fine. I am looking to display my images on the fly to resize them. How do I intergrate my image output string with the fly string. Current output echo '<img src="' . $dir . '/' . $image_id . '.jpg">'; Fly string <img src="/scripts/thumb.php?src=/images/whatever.jpg&h=150&w=150&zc=1" alt="" /> Thanks for your help Link to comment https://forums.phpfreaks.com/topic/234902-on-the-fly-help-display-image/ Share on other sites More sharing options...
Unirawan Posted April 27, 2011 Share Posted April 27, 2011 You can use PHP GD or PHP IMAGEMAJIC to process the image on the fly. Link to comment https://forums.phpfreaks.com/topic/234902-on-the-fly-help-display-image/#findComment-1207231 Share on other sites More sharing options...
Unirawan Posted April 27, 2011 Share Posted April 27, 2011 You can use PHP GD or PHP IMAGEMAJIC to process the image on the fly. that said, I highly recommend automatically creating thumbs once images are uploaded and directly accessing them thumbs, as it will save server resources, becasue you wont be using all that image processing cpu cycles and ram on each request. Link to comment https://forums.phpfreaks.com/topic/234902-on-the-fly-help-display-image/#findComment-1207236 Share on other sites More sharing options...
JKG Posted April 27, 2011 Share Posted April 27, 2011 i agree with dealing with the resize on upload, i have a nifty cropper and resize that i did a good while back <?php function CropImage($NewWidth, $NewHeight, $source, $filetype, $dest) { list($Width, $Height) = getimagesize($source); switch($filetype) { case 'gif': $SourceImage = imagecreatefromgif($source); break; case 'jpg': $SourceImage = imagecreatefromjpeg($source); break; case 'png': $SourceImage = imagecreatefrompng($source); break; } $NewImage = imagecreatetruecolor($NewWidth, $NewHeight); $WidthRatio = $Width/$NewWidth; $HeightRatio = $Height/$NewHeight; $HalfNewHeight = $NewHeight/2; $HalfNewWidth = $NewWidth/2; if($Width > $Height) { $AdjustedWidth = $Width / $HeightRatio; $HalfWidth = $AdjustedWidth / 2; $IntWidth = $HalfWidth - $HalfNewWidth; imagecopyresampled($NewImage, $SourceImage, -$IntWidth, 0, 0, 0, $AdjustedWidth, $NewHeight, $Width, $Height); } elseif(($Width < $Height) || ($Width == $Height)) { $AdjustedHeight = $Height / $WidthRatio; $HalfHeight = $AdjustedHeight / 2; $IntHeight = $HalfHeight - $HalfNewHeight; imagecopyresampled($NewImage, $SourceImage, 0, -$IntHeight, 0, 0, $NewWidth, $AdjustedHeight, $Width, $Height); } else { imagecopyresampled($NewImage, $SourceImage, 0, 0, 0, 0, $NewWidth, $NewHeight, $Width, $Height); } imagejpeg($NewImage, $dest, 100); } ?> feel free to use and abuse. Link to comment https://forums.phpfreaks.com/topic/234902-on-the-fly-help-display-image/#findComment-1207242 Share on other sites More sharing options...
lucan Posted April 27, 2011 Author Share Posted April 27, 2011 you are right changing bthe size on upload would be better but I need to use the same image a number of time with different sizes and location so I think on the fly would be best this time . Link to comment https://forums.phpfreaks.com/topic/234902-on-the-fly-help-display-image/#findComment-1207243 Share on other sites More sharing options...
JKG Posted April 27, 2011 Share Posted April 27, 2011 ok, so you understand Unirawan's first suggestion? Link to comment https://forums.phpfreaks.com/topic/234902-on-the-fly-help-display-image/#findComment-1207249 Share on other sites More sharing options...
QuickOldCar Posted April 27, 2011 Share Posted April 27, 2011 This can do what you need, follow the instructions and is lots of info there you can read if want to. http://phpthumb.sourceforge.net/ Link to comment https://forums.phpfreaks.com/topic/234902-on-the-fly-help-display-image/#findComment-1207256 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.