PHP Thumbnail Creation


Posted on 16th Feb 2014 07:03 pm by admin

Ok so i use this function to create thumbnails:

Code: [Select]function createthumb($name,$filename,$new_w,$new_h)
{
Did you know?Explore Trending and Topic pages for more stories like this.
$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?
No comments posted yet

Your Answer:

Login to answer
101 Like 38 Dislike
Previous forums Next forums
Other forums

Match stored value with the current value in a loop
Hello,

I have a MySQL db were I store articles in.

I have a form to fill these article

the problem with str_replace
$str="hahahahahahahahahahahahahaha";
$nn=1;
$str=str_replace('ha','MyGod',$str,$nn);

Compare user input to flat file data
Help...Am a complete newbie to programming so my code is prolly quite long. Am trying to verify a us

help with image text
Hi ...

see i need the text of the name and number to start in the center and always be in the

Function
How can I make this function that once you click the link in the code it takes you to a new page wit

limitations on array_unique()
Does any one know what/how imitations are applied to array_unique? I have an issue where no matter h

Parse Error Help
Hello, I got the parse error "Parse error: syntax error, unexpected ',' in register.php on line

problem in program for counting no of chars using pointers
Hi all, I was trying to make a program which counts number of chars in a string using concpt of poin

javascript in php code causes page to display white
Hi All,

Odd one this, I've got the following code (below) which is a simple log in form. The

Table trouble
i have been reading the forum for a few weeks and decided to join. i like the format and the advice

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash