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 Like 46 Dislike
Previous forums Next forums
Other forums

Object Interfaces
EDIT: Never mind, I just updated to php 5.

Hey all,

I'm currently experimenting with p

Material Master Update through BAPI - Follow up material not updated
Hi Experts,

I am updating the material master through a custom transaction using the BAPI

php mysql script to find record
Hi,

Currently I have a simple table with 4 columns. A, B, C, D

If I want to find all

How to add an image/C++ OpenGL?
Hi,

I have been trying to look online for this and, so far, I haven't found anything usef

Help on query replacing the date
Hi Pals,

i want to replace the current date in a column to some value say C or D or any n

pass form variables straight to email, no database required?
hello all,

im working on this form...

http://www.adobedayevents.com/project_request/pr

PHP Script runs on CLI but not through web browser
I am running into an issue that I just can't seem to find the answer to. I have a Windows Server 200

Need help to identify this error please
:confused:Can anyone help me tell what this error message means? Maybe tell me where to look to fix

strtotime issue
Hey all,

I'm playing around with some code, and basically the idea is:

Person changes

Need help making login verification cleaner...
I use the below to verify user login. I first check the cookie for the id, ip and a unique id. If it

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