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)
{
$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
ASP.NET Validation Event Cycle
Hi,
I have asp button as follow:Need help with a mail notify function
I was tasked with setting up a site that's been prewritten. The site is basically a form that captur
How to show the difference between two data field in a database with php.
Hello php gurus,
how r u all... i'm not so well facing a typical problem please help me...<
why isn't this PHP code working ???
it's suppose to find a name on the database.
<?php
$s = $_POST["lname&
Optimize Code
Just started getting into the use of cookies. The following code will redirect users to a set URL s
PHP Thumbnail Creation
Ok so i use this function to create thumbnails:
Code: [Select]function createthumb($name,$fil
Trouble checking SESSION cookie
I am trying to use $_SESSION cookies to verify admin privileges .
I don't understand why this is
Socket Server
In my following socket server, I am trying to listen to a connection through port 12345 in my web br
Displaying returned XML in another PHP page
I have an online payment form that will return XML given if a payment is successful or declines. I
Need help with an email blocker for a guessbook
I am new with php and here is a simple guessbook page but I am being hit with spam from a group of t