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
Page not Loading After Test
Hey All
It seemed that an inlcude statement wasn't working for some reason, so I tried a more
Sort a two dimensional array.
Hi. I've set up a two dimensional array that reads as follows:
Code: $modifiedData = array(
code help - pagination
Hi all, I have this code, basically a user logs into my site and they get this page.
The pro
Comparing two dates
Hi Guys
I have two dates I want to compare. Below is my current implementation. The problem with
Progress bar tracking file downloads
Hey guys, was wondering if there was a way to track how far a file has been downloaded. I know there
Regarding accessing SQL query issued by any user in Oracle 10g
Hi all,
i want to know the queries issued by various users accessing a database...
How to make a mail Form secure?
I want to create an email Form on my web site. How can I make the Form secure so the submitted info
Why is the logic of this simple code not working?
Hey, I'm trying to determine if a table already exists in mysql, but doing a query first with mysql_
Displaying a clickable playername
I am going wrong somewhere with the mysql_query, can someone please put me straight?
$playern
line breaks in between fetched file names
Hi,
I have this code:
Code: <?php
if($dir = opendir('files')){
while (($f