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)
{
$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

The control with ID 'ace' requires a ScriptManager on the page
I'm trying to add a simple AlwaysVisibleControlExtender to my page, but it's not working. I get the

update 2 columns by doing inner 2-column query
Hi,
is something like this possible?

update contract_all set col1,col2 =
(

Tournament Brackets (Double Elimination)?
Is making a double elimination tournament style bracket system capable of being done in php?

CU&UC guide
Hi Gurus,

can anybody provide me the link for CU&UC upgrade guide

Thanks i

retrieving more than one max key from an array?
so i have an array of 20 numerical values (0-100) that i need to order from highest to lowest and th

MySQL issue
I am taking sentences through a form on page. Then checking some condition and trying to insert them

displaying unknown amount of results
I am reading a directory and getting a list of folders in the directory, I want to display the folde

Email "$"
Hello!!

Any PHP guy with a bit of a knowledge in Flash ?

When I send a JPEG from flash

How to Handle more than one submit button in single form?
Hi
I have one PHP file which contains one Form. In this form there are two Submit type Buttons

Can't shake the "Warning: include()" error
I've just uploaded my site to a new server and where I have PHP include tags in my HTML, the browser

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