PHP Thumbnail Creation
Posted on
16th Feb 2014 07:03 pm by
admin
Ok so i use this function to create thumbnails:
Code: 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
347
46
Other forums
How to ... (FAQs)
... get e-mail notifications
As several people asked how to get e-mail notifications when new posti
radio button reamains checked
Hello i'm trying to keep the state off my radio buttons so it shows which ones where clicked after t
Add 5 to a variable when a button is clicked, and re-run a for loop
So I'm making a feedback sort of section on a website with MySQL and PHP, I've gotten the script to
IP Based Cron Jobs
I run cronjobs on my website. After one of my visitors got curious and tinkered around he realized h
problems with php variables in mysql query
i can't seem to get the following query to work.
select $q1c from $vote_rate where id = $re
having probem inserting data into db table
hi
i have a table with following columns in it
Code: candidate_id, degree, cgpa, institute
Securing a user input - need some confirmation
Hello All,
I am in the process of recoding a large proportion of an e-commerce site, one of t
Just a white page
Okay so, my website, when I click SignUp on it it takes me to /join.php but its a complete white pag
Turning Data into URLs?
This may seem very basic to you, but I'm having a hard time figuring out how to do this since I don'
What are the two different files you download to update kernel?
What are the two different files you download to update kernel?