Fabis94 Posted October 20, 2009 Share Posted October 20, 2009 Ok so i use this function to create thumbnails: function createthumb($name,$filename,$new_w,$new_h) { $system=explode('.',$name); $src_img=imagecreatefrompng($name); $old_x=imageSX($src_img); $old_y=imageSY($src_img); if ($old_x > $old_y) { $thumb_w=$new_w; $thumb_h=$old_y*($new_h/$old_x); } if ($old_x < $old_y) { $thumb_w=$old_x*($new_w/$old_y); $thumb_h=$new_h; } if ($old_x == $old_y) { $thumb_w=$new_w; $thumb_h=$new_h; } $dst_img=ImageCreateTrueColor($thumb_w,$thumb_h); imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); if (preg_match("/png/",$system[1])) { imagepng($dst_img,$filename); } else { imagejpeg($dst_img,$filename); } imagedestroy($dst_img); imagedestroy($src_img); } It works and all, but the problem is that for my gallery i need all the pictures to be exactly 150x150, but i also need the images to keep their aspect ratio (so they don't look ugly) so i was thinking i could add like borders that would fill up the space. Ok imagine the function resizes the image to 100x150 so i make the image centered and add 50px wide white black borders on each side of the picture, so it isn't stretched out (keeps it's ratio) and is also 150x150. The question is, how do i do this? Quote Link to comment https://forums.phpfreaks.com/topic/178352-solved-php-thumbnail-creation/ Share on other sites More sharing options...
Alex Posted October 20, 2009 Share Posted October 20, 2009 First you would need to create a new image resource using imagecreatetruecolor(). Then using imagefill() you can fill it with black color. Finally use imagecopymerge(), along with a bit of math, to merge the two images together placing it in the center. Quote Link to comment https://forums.phpfreaks.com/topic/178352-solved-php-thumbnail-creation/#findComment-940475 Share on other sites More sharing options...
Bricktop Posted October 20, 2009 Share Posted October 20, 2009 Hi Fabis94, It would be easier to use CSS to achieve this. For example, output the image in the normal way inside a DIV with a "class" tag, for example: <div class="imageborder"><img src="image.jpg" alt="Some Image" /></div> Then, in your CSS file have something like: .imageborder { width: 150px; height: 150px; text-align:center; vertical-align: middle; border: 1px solid #000000; } Something like that should work. Hope this helps. Quote Link to comment https://forums.phpfreaks.com/topic/178352-solved-php-thumbnail-creation/#findComment-940481 Share on other sites More sharing options...
Fabis94 Posted October 20, 2009 Author Share Posted October 20, 2009 Hi Fabis94, It would be easier to use CSS to achieve this. For example, output the image in the normal way inside a DIV with a "class" tag, for example: <div class="imageborder"><img src="image.jpg" alt="Some Image" /></div> Then, in your CSS file have something like: .imageborder { width: 150px; height: 150px; text-align:center; vertical-align: middle; border: 1px solid #000000; } Something like that should work. Hope this helps. It would work for me, but the image will be used as a link, so i need the whole area (150x150) to be clickable as the link. If i use your way, only when you click on the image you will be lead to the links destination, not the whole 150x150 area. Also i don't quite understand how imagecopymerge() works (i checked the docs). Quote Link to comment https://forums.phpfreaks.com/topic/178352-solved-php-thumbnail-creation/#findComment-940488 Share on other sites More sharing options...
Bricktop Posted October 20, 2009 Share Posted October 20, 2009 Hi Fabis94, If you define a class to the link code, and then use display: block; in your CSS that should ensure the whole area is clickable. i.e.: .link { display: block; } Hope this helps. Quote Link to comment https://forums.phpfreaks.com/topic/178352-solved-php-thumbnail-creation/#findComment-940497 Share on other sites More sharing options...
redarrow Posted October 20, 2009 Share Posted October 20, 2009 But 1 min Alex, posted the image function for gd, You require thinking you was learning php as you went along ? Quote Link to comment https://forums.phpfreaks.com/topic/178352-solved-php-thumbnail-creation/#findComment-940498 Share on other sites More sharing options...
Fabis94 Posted October 20, 2009 Author Share Posted October 20, 2009 But 1 min Alex, posted the image function for gd, You require thinking you was learning php as you went along ? ... What? Quote Link to comment https://forums.phpfreaks.com/topic/178352-solved-php-thumbnail-creation/#findComment-940507 Share on other sites More sharing options...
Dorky Posted October 20, 2009 Share Posted October 20, 2009 a { width: 150px; height: 150px; overflow: hidden; } <a href='whateverifelllikedoing' target='momoney'><img src='yourproblem' /></a> or use the image commands in php to do as suggested and create a colored box and copy the image onto that. you will learn more and go farther to do this. the overflow trick is a shortcut. Quote Link to comment https://forums.phpfreaks.com/topic/178352-solved-php-thumbnail-creation/#findComment-940508 Share on other sites More sharing options...
Fabis94 Posted October 20, 2009 Author Share Posted October 20, 2009 Ok i did it with PHP (imagecopy() function). Thanks for help everyone Quote Link to comment https://forums.phpfreaks.com/topic/178352-solved-php-thumbnail-creation/#findComment-940524 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.