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?
101
38
Other php-forum
PHP SUBMIT
Code: <input name="doLogin" type="image" src="images/loginsubmit.jpg
PHP friend keyword equivalent
is there a PHP equivalent for the C++ friend keyword?
adding 0 to numbers
Hey guys i need to create a 00001 number in a loop. Is there a better way of forcing a 5 digit numbe
Echo Tweaking help!
HI. I would like to have the output of the entered variables repeat forever, but it's stopping at th
ctype() validation - allowing illegal characters
Hello,
I use ctype() to filter and validate a user form. However, I am trying to allow certain c
PHP Code reffering to database, doing something wrong.. pls help
Well i am quite new with PHP
and for school we have to make a PHP script which reffers to a Data
$_FILES array
Ok,
I just started experimenting with PHP today. My goal right now is to have people be able
mail with attachment problems
Hi. I have the following code:
Code: else if(file_exists("site".$timp.".zip")
Creating web pages by php
Hello again,
I was just wondering us there a way to use a php script to create a new web page. I
Cloud Computing?
Hello,
I was wondering if anyone could help explain this term to me. I'm starting to hear it