ฟังก์ชั่นรีไซด์รูปภาพ

PHP Result Center PHP Result Center เป็นหมวด ที่ไว้รวบรวม โปรแกรม Code php Javascript CSS CMS

Moderators: mindphp, ผู้ดูแลกระดาน

touleg
PHP Super Member
PHP Super Member
Posts: 480
Joined: 25/01/2010 11:57 pm
Contact:

ฟังก์ชั่นรีไซด์รูปภาพ

Post by touleg »

Code: Select all

function resize($path,$fileName,$width)
    { 
        $size=getimagesize($path.$fileName);
        $height=round($width*$size[1]/$size[0]);
        $new_images=imgRename($fileName);
        $file = explode('.',$new_images);
        $type = $file[count($file)-1];
        $images_fin = imagecreatetruecolor($width, $height);
        
        if($type=="jpg")
        {
            $images_orig = imagecreatefromjpeg($path.$fileName);
            imagecolorallocate($images_fin,255,255,255);
        }else if($type=="gif"){
            $images_orig = imagecreatefromgif($path.$fileName);
            imagecolorallocate($images_fin,255,255,255);
        }else{
            $images_orig = imagecreatefrompng($path.$fileName);
            $transparent = imagecolorallocatealpha($images_fin, 255, 255, 255,127);
            imagealphablending($images_fin, false);
            $bg = imagecolortransparent($images_fin,$transparent);
            imagefill($images_fin, 0, 0, $bg);
        }
        
        $photoX = imagesx($images_orig);
        $photoY = imagesy($images_orig);
        
        imagecopyresized($images_fin, $images_orig, 0, 0, 0, 0, $width+1, $height+1, $photoX, $photoY);
        
        if($type=="jpg")
        {
            imagejpeg($images_fin,$path.$new_images);
        }else if($type=="gif"){
            imagegif($images_fin,$path.$new_images);
        }else{
            imagesavealpha($images_fin, true);
            imagepng($images_fin,$path.$new_images);
        }
        imagedestroy($images_orig);
        imagedestroy($images_fin);
        unlink($path.$fileName);
    }
    
    function imgRename($filename)
    {
        $file = explode('.',$filename);
        $fileType = $file[count($file)-1];
        
         return md5(date("U")).".".$fileType;
    }
 
Last edited by touleg on 06/04/2012 9:35 pm, edited 1 time in total.

ballball
PHP Newbie
PHP Newbie
Posts: 1
Joined: 03/04/2012 4:48 pm
Contact:

Re: ฟังก์ชั่นรีไซด์รูปภาพ

Post by ballball »

กำลังหาอยู่เล ขอบคุณมากครับ

Post Reply

Return to “Free PHP Code Download script”

Who is online

Users browsing this forum: No registered users and 4 guests