Thursday, 09 February 2012

function resize image

Category : PHP Script
function untuk melakukan resize image secara langsung..
misalnya kita memperbolehkan pengunjung kita untuk upload gambar dia, tapi karena terbatasnya space server kita, maka kita harus melakukan resize terhadap gambar tersebut.
inilah function yang bisa melakukan itu..

parameter yang di butuhkan,
$source = letak dari gambar tersebut,
$dest  = tujuan dari gambar tersebut di simpan
$newW = lebar baru dari gambar
$newH = tinggi baru dari gambar

untuk  bisa menjalankan function ini dibutuhkan extentions gd2.dll (windows) atau gd2.so (linux)

<?
function resizeImage($source,$dest,$newW,$newH)
    {                   
        list($width, $height, $image_type) = getimagesize($source);       
       
        if ($image_type == "2")
        {
            $image_p = imagecreatetruecolor($newW, $newH);
            $image = imagecreatefromjpeg($source);
        }
        else if ($image_type == "1")
        {
            $image_p = imagecreate($newW, $newH);
            $image = imagecreatefromgif($source);
            $colorTransparent = imagecolortransparent($image);
            imagepalettecopy($image_p,$image);
            imagefill($image_p,0,0,$colorTransparent);
            imagecolortransparent($image_p, $colorTransparent);
        }
        imagecopyresampled($image_p, $image, 0, 0, 0, 0, $newW, $newH, $width, $height);
       
        if ($image_type == "2")
            imagejpeg($image_p, $dest, 100);
        else if ($image_type == "1")
            imagegif($image_p, $dest, 100);       
    }

// contoh cara pengunaan pada umumnya
resizeImage($_FILES['source']['tmp_name'],'folder/image',100,100);
?>
dengan mengunakan function ini kita tak perlu mengunakan fungsi copy lagi, karena function ini akan secara otomatis membuat suatu gambar baru.

Like this articles? share it with Share With FacebookFacebook
<< Back
0 Comment | 1364 hits | Posted by Callrid at 2006-11-29 10:30:51

Related Read

Add Comment
Name :
Web :
Comment :

Code :
 

Other Source
A Practical Guide On Complete Multivitamins
Many of us have a hard time deciding what the best multivitamin is for us. This is completely confusing and difficult especially when there are so many bottles to scan in the various aisles of the...

High Blood Pressure
The nutritional benefits of low-fat dairy products are well known for ages. The latest studies show that the ingredients of dairy products - some combination of milk proteins are effective and...

Welcome To Mimicwatch.com - Quality Luxury Replica Vacheron Constantin Watches At Affordable Price
When entering our online store at Mimicwatch.com, you are given an unique opportunity to choose among a wide selection of famous Replica Watches and Replica handbags such as Replica Vacheron...

Ebook Marketing Tips
A great way to have a product to sell on the Internet is an e-book which almost anyone can create. There is no longer any need for delaying with the simple process detailed below. If you are afraid...

Tactical Asset Marketing
Asset Management Different Asset Allocation Strategies Asset marketing is the process of dividing a portfolio into major asset categories such as cash, stocks, real estate, or...

Shout Box
2012-02-06 19:57:17 
rumah dijual
selalu dagdigdug kalau bertemu dia
2012-02-03 05:38:35 
mobil bekas
jalan-jalan
2012-02-02 19:39:38 
Meilani
wkwkwkwkwk
2012-02-01 12:38:12 
Software Akuntansi
Software Akuntansi Laporan Keuangan Terbaik
2012-01-27 13:53:07 
CEndy Bellyone
keRRen cEndy hampir nangis T-T
Callrid : Kenapa?

Site Partners


Search Articles

Web Statistic
No Visitor :
2709771
Today Visitor :
2438
Online Visitor :
1
what is my ip address? Page Rank Checker

< Feb 2012 >
SMTWTFS
   1234
567891011
12131415161718
19202122232425
26272829

Increase Page Rank

Last Modified 08-November-2011, 23:21:04 pm
callrid.com Created 2006-2010 by Anton Ongsono
All rights reserved