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
38
Other forums
Having Problem with Date
l have a submit buttom where user have the possibility to add a date to specify when his message s
connect() succeeds but accept() does not?
Please help me with this problem. I'm working on a time-sensitive project where I'm using TCP socket
function to return url
Hi,
Can you guys help me giving a function that takes all the contents in a particular field
urldecode question
How would I format this line of code properly?
<?php echo urldecode($_GET['Title']); ?
how to read and write into a word document using php...?
hi,
I need,reading and writting into a word document using php.
Thank u inadva
Simple MySQL script is not working
Hey guys,
Just familiarizing myself with PHP and MySQL. I am following along in the O'Reilly
Array to string conversion
Can anyone help me with this?
Notice: Array to string conversion in /home/..../index.php on l
include problem
I have my root folder as:
Code: $root = $_SERVER["SITE_HTMLROOT"]; // the server root<
Sum of Values in an Array
This is probably really simple... but it's been years since I've written anything, so bare with me!<
Operator precedence assistance.
I did a quick Google search and couldn't quite find the answer I wanted in terms I could understand,