Webmaster Forumu  

Go Back   Webmaster Forumu > Grafik Tasarım & Programlama > Php

Php Php Kodlama Dili Hakkında Bilgiler

Cevapla
 
LinkBack Seçenekler Stil
Alt 08-08-2011, 15:48   #1
 
Amasya Şubesi
Mesajlar: 795
Tecrübe Puanı: 1
Rep Puanı: 10
Rep Derecesi : WebLog
Standart Resim Yüklerken Küçük Resim Oluşturma Kodu

Kod:
  <? 
############################################## 
# Shiege Iseng Resize Class 
# 11 March 2005 
# shiegegeATyahoo.com 
# http://shiege.com/scripts/thumbnail/ 
/*############################################ 
Sample : 
$thumb=new thumbnail("./shiegege.jpg");            // generate image_file, set filename to resize/resample 
$thumb->size_width(100);                        // set width for thumbnail, or 
$thumb->size_height(300);                        // set height for thumbnail, or 
$thumb->size_auto(200);                            // set the biggest width or height for thumbnail 
$thumb->jpeg_quality(75);                        // [OPTIONAL] set quality for jpeg only (0 - 100) (worst - best), default = 75 
$thumb->show();                                    // show your thumbnail 
$thumb->save("./huhu.jpg");                        // save your thumbnail to file 
---------------------------------------------- 
Note : 
- GD must Enabled 
- Autodetect file extension (.jpg/jpeg, .png, .gif, .wbmp) 
  but some server can't generate .gif / .wbmp file types 
- If your GD not support 'ImageCreateTrueColor' function, 
  change one line from 'ImageCreateTrueColor' to 'ImageCreate' 
  (the position in 'show' and 'save' function) 
- If your GD not support 'ImageCopyResampled' function, 
  change 'ImageCopyResampled' to 'ImageCopyResize' 
*/############################################ 


class thumbnail 
{ 
    var $img; 

    function thumbnail($imgfile) 
    { 
        //detect image format 
        $this->img["format"]=ereg_replace(".*\.(.*)$","\\1",$imgfile); 
        $this->img["format"]=strtoupper($this->img["format"]); 
        if ($this->img["format"]=="JPG" || $this->img["format"]=="JPEG") { 
            //JPEG 
            $this->img["format"]="JPEG"; 
            $this->img["src"] = ImageCreateFromJPEG ($imgfile); 
        } elseif ($this->img["format"]=="PNG") { 
            //PNG 
            $this->img["format"]="PNG"; 
            $this->img["src"] = ImageCreateFromPNG ($imgfile); 
        } elseif ($this->img["format"]=="GIF") { 
            //GIF 
            $this->img["format"]="GIF"; 
            $this->img["src"] = ImageCreateFromGIF ($imgfile); 
        } elseif ($this->img["format"]=="WBMP") { 
            //WBMP 
            $this->img["format"]="WBMP"; 
            $this->img["src"] = ImageCreateFromWBMP ($imgfile); 
        } else { 
            //DEFAULT 
            echo "Not Supported File"; 
            exit(); 
        } 
        @$this->img["lebar"] = imagesx($this->img["src"]); 
        @$this->img["tinggi"] = imagesy($this->img["src"]); 
        //default quality jpeg 
        $this->img["quality"]=75; 
    } 

    function size_height($size=100) 
    { 
        //height 
        $this->img["tinggi_thumb"]=$size; 
        @$this->img["lebar_thumb"] = ($this->img["tinggi_thumb"]/$this->img["tinggi"])*$this->img["lebar"]; 
    } 

    function size_width($size=100) 
    { 
        //width 
        $this->img["lebar_thumb"]=$size; 
        @$this->img["tinggi_thumb"] = ($this->img["lebar_thumb"]/$this->img["lebar"])*$this->img["tinggi"]; 
    } 

    function size_auto($size=100) 
    { 
        //size 
        if ($this->img["lebar"]>=$this->img["tinggi"]) { 
            $this->img["lebar_thumb"]=$size; 
            @$this->img["tinggi_thumb"] = ($this->img["lebar_thumb"]/$this->img["lebar"])*$this->img["tinggi"]; 
        } else { 
            $this->img["tinggi_thumb"]=$size; 
            @$this->img["lebar_thumb"] = ($this->img["tinggi_thumb"]/$this->img["tinggi"])*$this->img["lebar"]; 
         } 
    } 

    function jpeg_quality($quality=75) 
    { 
        //jpeg quality 
        $this->img["quality"]=$quality; 
    } 

    function show() 
    { 
        //show thumb 
        @Header("Content-Type: image/".$this->img["format"]); 

        /* change ImageCreateTrueColor to ImageCreate if your GD not supported ImageCreateTrueColor function*/ 
        $this->img["des"] = ImageCreateTrueColor($this->img["lebar_thumb"],$this->img["tinggi_thumb"]); 
            @imagecopyresampled ($this->img["des"], $this->img["src"], 0, 0, 0, 0, $this->img["lebar_thumb"], $this->img["tinggi_thumb"], $this->img["lebar"], $this->img["tinggi"]); 

        if ($this->img["format"]=="JPG" || $this->img["format"]=="JPEG") { 
            //JPEG 
            imageJPEG($this->img["des"],"",$this->img["quality"]); 
        } elseif ($this->img["format"]=="PNG") { 
            //PNG 
            imagePNG($this->img["des"]); 
        } elseif ($this->img["format"]=="GIF") { 
            //GIF 
            imageGIF($this->img["des"]); 
        } elseif ($this->img["format"]=="WBMP") { 
            //WBMP 
            imageWBMP($this->img["des"]); 
        } 
    } 

    function save($save="") 
    { 
        //save thumb 
        if (empty($save)) $save=strtolower("./thumb.".$this->img["format"]); 
        /* change ImageCreateTrueColor to ImageCreate if your GD not supported ImageCreateTrueColor function*/ 
        $this->img["des"] = ImageCreateTrueColor($this->img["lebar_thumb"],$this->img["tinggi_thumb"]); 
            @imagecopyresampled ($this->img["des"], $this->img["src"], 0, 0, 0, 0, $this->img["lebar_thumb"], $this->img["tinggi_thumb"], $this->img["lebar"], $this->img["tinggi"]); 

        if ($this->img["format"]=="JPG" || $this->img["format"]=="JPEG") { 
            //JPEG 
            imageJPEG($this->img["des"],"$save",$this->img["quality"]); 
        } elseif ($this->img["format"]=="PNG") { 
            //PNG 
            imagePNG($this->img["des"],"$save"); 
        } elseif ($this->img["format"]=="GIF") { 
            //GIF 
            imageGIF($this->img["des"],"$save"); 
        } elseif ($this->img["format"]=="WBMP") { 
            //WBMP 
            imageWBMP($this->img["des"],"$save"); 
        } 
    } 
} 
?>
  
  ustteki kodu resize.txt olarak kayıt edin.

kullanımı
  
  <? 
include("resize.txt");                     //include class 
$thumb=new thumbnail("./shiegege.jpg");    // generate shiegege.jpg 

if ($_GET["size"]<50 || $_GET["size"]>500) {   // 50-500 pixels will resize 
    echo "resize range 50 pixels - 500 pixels";    exit(); 
} 

if ($_GET["mode"]=="height") {               // mode resize 
    $thumb->size_height($_GET["size"]); 
} elseif ($_GET["mode"]=="width") { 
    $thumb->size_width($_GET["size"]); 
} elseif ($_GET["mode"]=="auto" || empty($_GET["mode"])) { 
    $thumb->size_auto($_GET["size"]); 
} 

$thumb->show();                            // show resize 

if ($_GET["save"]==1)                        // if save selected 
    $thumb->save("./shiegege_thumb.jpg"); 
?> [/PHP] 

Bende bu şekilde kullanıyorum. 

[PHP]<? 
include("resize.txt");   
$thumb=new thumbnail("./resim1.JPG");// Küçülecek resim 
$thumb->size_width(94);  // genişliği 94px yapar eğer aşağıdaki kod varsa bunu dikkate almaz 
$thumb->size_height(56); // yüksekliği 56px yapar eğer aşağıdaki kod varsa bunu dikkate almaz 
$thumb->size_auto(200); // genişliğini 200 yapıp orantılı olarak boyunuda kısaltır 
$thumb->jpeg_quality(75);// Resim kalitesi 75 önerilir 1 ile 100 arasında rakam girilir orjinalliğe göre 
$thumb->show();// göster demek :) Küçük resmi 
$thumb->save("./resim1_kucuk.jpg");    //küçülen resmin adı 
?>
  
  Saygılar..
WebLog isimli Üye şimdilik offline konumundadır   Alıntı ile Cevapla
Sponsored Links
Cevapla


Konuyu Toplam 1 Üye okuyor. (0 Kayıtlı üye ve 1 Misafir)
 
Seçenekler
Stil

Yetkileriniz
Konu Acma Yetkiniz Yok
Cevap Yazma Yetkiniz Yok
Eklenti Yükleme Yetkiniz Yok
Mesajınızı Değiştirme Yetkiniz Yok

BB code is Açık
Smileler Açık
[IMG] Kodları Açık
HTML-Kodu Kapalı
Trackbacks are Açık
Pingbacks are Açık
Refbacks are Açık



Tüm Zamanlar GMT +3 Olarak Ayarlanmış. Şuanki Zaman: 03:48.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0 ©2011, Crawlability, Inc.