FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


How to Reduce an Images Size with php





Possum
Hi

I can resize an image in Pascal

Code:
StretchBlt(Destination_Bitmap.Canvas.Handle,0,0,Image_Destination.Width, Image_Destination.Height,Source_Bitmap.Canvas.Handle, 0, 0, Source_Bitmap.Width,Source_Bitmap.Height, SRCCOPY );   


But how can I do this in php..

The reason I am asking is because I am writing a Web app and Native app that do almost the same thing..

thx..
sonam
I know basic way how to resize image, but I am always using this images in fly without saving. Here is one article what looking useful.

http://icant.co.uk/articles/phpthumbnails/

Sonam
jmlworld
Use Timthumb. http://code.google.com/p/timthumb

Though timthumb was initially intended to crop images for magazine style WordPress themes, but since WP2.8/9 its use was dropped due to the new version of WordPress using a built-in feature.

The project is still active and it doesn't depend on WordPress functions/features to run and you can use it for any PHP project you want as long as you're running PHP >= 5.


You can crop an image by calling the timthumb like this:

Code:

<img src="http://site/library/timthumb.php?src=http://site/img/big_image.jpg&h=100&w=100&q=100" />


The above example outputs cropped image.

The cropping paramaters are:

w: width
h: height
q: quality

All sizes are in pixels.

You should create a cache folder to store cropped images. Original images will not be touched.

You cannot resize remote images unless you whitelist them first. This is obviously a security feature.

Read the documentation at: http://code.google.com/p/timthumb/wiki/HowTo
Possum
THX EVERYONE..

I though there would be a php equivalent in exact php code. But its all good

thank you..
chatrack
Hi,

You can use GD function of php and reduce the size.
I think you will agree with the quality of thumbnail image
metalfreek
You can take some reference from timthumb script as well. Its very popular among wordpress themes creators.
jeanfox
yah.. they're right.. in present,, we use an image resizer scripts, its about 20kb below.. a very simple codes w/c a powerful function for graphics and styling..
Aredon
Actually... that somewhat depends on what you're aiming for. Are you trying to permanently resize the image from upload, or are you trying to take an image that is one size in your database and display it as another size on the site. (thumbnail) If you're looking for a thumbnail script I found one a while ago after several days of digging, and I can post that here later if you're interested. (In use here http://amicitia.frih.net/gallery.php)
jetgirltaxi
Here's something from a photo book script I wrote. It resizes an images to a given pixel width, default of 160.

Code:

function resizeJPG($jpgFile, $newfile, $width = 160)
    {
    // Get new dimensions
    list($width_orig, $height_orig) = getimagesize($jpgFile);
    $height = (int) (($width / $width_orig) * $height_orig);

    // Resample
    $image_p = imagecreatetruecolor($width, $height);
    $image = imagecreatefromjpeg($jpgFile);
    imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);

    // Output
    imagejpeg($image_p, $newfile, 100);

    // free image resources
    imagedestroy($image_p);
    imagedestroy($image);
   
    return true;
    }


Hope it helps.
ogah
timthumb have security hole.
if you want to use timthumb maybe this one useful to make extra timthumb protection
http://protect-timthumb.xtgem.com/
Related topics
[tutor] How to protect images without htaccess using PHP
all images appear corrupt!
Avatar Size
creating pages
The Perfect Audio Rips
Images In PHP
TUTORIAL => Compress your BSP Files with BZIP2
Includ Images using PHP.
My review site
my site
Uplaoding images using php form :::: Help needed
www.karmasarmy.net
Help needed with images in php include files
How to make an image weight the smallest possible!!!
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.