Anasayfa FORUMLAR Üye Girişi Dosyalar Dersler İpuçları Yardımcı Araçlar Hakkımızda
KİMLER BAĞLI
Toplam Üye: 32638
Aktif Üye: 0
Aktif Ziyaretçi: 738
Üye Adı
Şifre
Beni Hatırla
          Yeni Üye KayıtYeni Üye Kayıt
          Şifremi UnuttumŞifremi Unuttum
FORUMLAR
 acil web sayfa boyutu ner..
(4845 okuma, 3 yanıt)
 uye adina gore veri cekme..
(4061 okuma, 1 yanıt)
 Ajax vb. Manşet Scripti?..
(4931 okuma, 2 yanıt)
 Random banner nasıl yapar..
(3703 okuma, 1 yanıt)
 Veritabanına Alan Eklemek..
(3319 okuma, 0 yanıt)
 downlaod sitesi için hazı..
(7003 okuma, 7 yanıt)
 popup sayfa lütfen yardım..
(3552 okuma, 0 yanıt)
 youtube indirici getten g..
(5637 okuma, 2 yanıt)
 Hicri Takvime göre Tarih ..
(3043 okuma, 0 yanıt)
 Telefon Rehberi..
(3500 okuma, 0 yanıt)
 dosya indirirken 10 saniy..
(3865 okuma, 2 yanıt)
 switch komutu çalıştırama..
(3334 okuma, 0 yanıt)
 Bu kodun neresine rel=nof..
(6843 okuma, 8 yanıt)
 include ve require kod ha..
(7207 okuma, 8 yanıt)
 Remote File İnclude - RFI..
(5739 okuma, 4 yanıt)
 php de form dan gönderile..
(6167 okuma, 5 yanıt)
 Otomatik Şifre Üretimi..
(4052 okuma, 1 yanıt)
 PHP ile resim boyutu ayar..
(6916 okuma, 4 yanıt)
 Rastgele Şifre Üretmek..
(4116 okuma, 2 yanıt)
 klasördeki resimleri php ..
(8692 okuma, 9 yanıt)
 PHP Bilgisini Öğrenelim..
(11105 okuma, 12 yanıt)
 Php Ekşin - Php'ye Giriş ..
(5660 okuma, 4 yanıt)
 firefox harici kişilere &..
(3625 okuma, 0 yanıt)
 BB-Code Fonksiyonu..
(4658 okuma, 2 yanıt)
 PHP ile PNG resim oluştur..
(5245 okuma, 2 yanıt)
 Rastgele Şifre Üretmek..
(7011 okuma, 5 yanıt)
 Dizin okuma,dosyalarıdizm..
(3668 okuma, 0 yanıt)
 PHP'nin Yapı Taşları..
(3968 okuma, 0 yanıt)
 Php ye giriş..
(4190 okuma, 0 yanıt)
 Google gibi Otomatik dil ..
(9335 okuma, 11 yanıt)
Netopsiyon Online: Forums
Netopsiyon Online :: Başlık görüntüleniyor - PHP ile resim boyutu ayarlama
 AramaArama   RütbelerRütbeliler   ProfilProfil   GirişGiriş 


PHP ile resim boyutu ayarlama

 
Bu forum kilitlendi: mesaj gönderemez, cevap yazamaz ya da başlıkları değiştiremezsiniz   Bu başlık kilitlendi: mesajları değiştiremez ya da cevap yazamazsınız    Netopsiyon Online Forum Ana Sayfa -> PHP -> PHP Kod Örnekleri
Önceki başlık :: Sonraki başlık  
Yazar Mesaj
Aliosman
Teknik Yönetici
Teknik Yönetici





Kayıt: Jul 20, 2002
Mesajlar: 3836
Konum: Balıkesir

MesajTarih: 2006-08-23, 21:47:58    Mesaj konusu: PHP ile resim boyutu ayarlama Alıntıyla Cevap Gönder

Bu konuda birçok örnek vereceğim.
Kod:
<?php
// File and new size
$filename = 'test.jpg';
$percent = 0.5;

// Content type
header('Content-type: image/jpeg');

// Get new sizes
list($width, $height) = getimagesize($filename);
$newwidth = $width * $percent;
$newheight = $height * $percent;

// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);

// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

// Output
imagejpeg($thumb);
?>

Kod:
<?php
function Resize($Dir,$Image,$NewDir,$NewImage,$MaxWidth,$MaxHeight,$Quality) {
  list($ImageWidth,$ImageHeight,$TypeCode)=getimagesize($Dir.$Image);
  $ImageType=($TypeCode==1?"gif":($TypeCode==2?"jpeg":
             ($TypeCode==3?"png":FALSE)));
  $CreateFunction="imagecreatefrom".$ImageType;
  $OutputFunction="image".$ImageType;
  if ($ImageType) {
   $Ratio=($ImageHeight/$ImageWidth);
   $ImageSource=$CreateFunction($Dir.$Image);
   if ($ImageWidth > $MaxWidth || $ImageHeight > $MaxHeight) {
     if ($ImageWidth > $MaxWidth) {
         $ResizedWidth=$MaxWidth;
         $ResizedHeight=$ResizedWidth*$Ratio;
     }
     else {
       $ResizedWidth=$ImageWidth;
       $ResizedHeight=$ImageHeight;
     }       
     if ($ResizedHeight > $MaxHeight) {
       $ResizedHeight=$MaxHeight;
       $ResizedWidth=$ResizedHeight/$Ratio;
     }     
     $ResizedImage=imagecreatetruecolor($ResizedWidth,$ResizedHeight);
     imagecopyresampled($ResizedImage,$ImageSource,0,0,0,0,$ResizedWidth,
                         $ResizedHeight,$ImageWidth,$ImageHeight);
   }
   else {
     $ResizedWidth=$ImageWidth;
     $ResizedHeight=$ImageHeight;     
     $ResizedImage=$ImageSource;
   }   
   $OutputFunction($ResizedImage,$NewDir.$NewImage,$Quality);
   return true;
  }   
  else
   return false;
}
?>

Kod:
<?php
/**********************************************************
 * function resizejpeg:
 *
 *  = creates a resized image based on the max width
 *    specified as well as generates a thumbnail from
 *    a rectangle cut from the middle of the image.
 *
 *    @dir  = directory image is stored in
 *    @img  = the image name
 *    @max_w = the max width of the resized image
 *    @max_h = the max height of the resized image
 *    @th_w  = the width of the thumbnail
 *    @th_h  = the height of the thumbnail
 *
 **********************************************************/

function resizejpeg($dir, $img, $max_w, $max_h, $th_w, $th_h)
{
   // get original images width and height
   list($or_w, $or_h, $or_t) = getimagesize($dir.$img);

   // make sure image is a jpeg
   if ($or_t == 2) {
   
       // obtain the image's ratio
       $ratio = ($or_h / $or_w);

       // original image
       $or_image = imagecreatefromjpeg($dir.$img);

       // resize image
       if ($or_w > $max_w || $or_h > $max_h) {

           // first resize by width (less than $max_w)
           if ($or_w > $max_w) {
               $rs_w = $max_w;
               $rs_h = $ratio * $max_h;
           } else {
               $rs_w = $or_w;
               $rs_h = $or_h;
           }

           // then resize by height (less than $max_h)
           if ($rs_h > $max_h) {
               $rs_w = $max_w / $ratio;
               $rs_h = $max_h;
           }

           // copy old image to new image
           $rs_image = imagecreatetruecolor($rs_w, $rs_h);
           imagecopyresampled($rs_image, $or_image, 0, 0, 0, 0, $rs_w, $rs_h, $or_w, $or_h);
       } else {
           $rs_w = $or_w;
           $rs_h = $or_h;

           $rs_image = $or_image;
       }
   
       // generate resized image
       imagejpeg($rs_image, $dir.$img, 100);

       $th_image = imagecreatetruecolor($th_w, $th_h);

       // cut out a rectangle from the resized image and store in thumbnail
       $new_w = (($rs_w / 4));
       $new_h = (($rs_h / 4));

       imagecopyresized($th_image, $rs_image, 0, 0, $new_w, $new_h, $rs_w, $rs_h, $rs_w, $rs_h);

       // generate thumbnail
       imagejpeg($th_image, $dir.'thumb_'.$img, 100);

       return true;
   }
   
   // Image type was not jpeg!
   else {
       return false;
   }
}
?>

Example:

<?php
$dir = './';
$img = 'test.jpg';

resizejpeg($dir, $img, 600, 600, 300, 150);
?>
Kod:
<?

function thumb($filename, $destination, $th_width, $th_height, $forcefill)
{   
   list($width, $height) = getimagesize($filename);

   $source = imagecreatefromjpeg($filename);

   if($width > $th_width || $height > $th_height){
     $a = $th_width/$th_height;
     $b = $width/$height;

     if(($a > $b)^$forcefill)
     {
         $src_rect_width  = $a * $height;
         $src_rect_height = $height;
         if(!$forcefill)
         {
           $src_rect_width = $width;
           $th_width = $th_height/$height*$width;
         }
     }
     else
     {
         $src_rect_height = $width/$a;
         $src_rect_width  = $width;
         if(!$forcefill)
         {
           $src_rect_height = $height;
           $th_height = $th_width/$width*$height;
         }
     }

     $src_rect_xoffset = ($width - $src_rect_width)/2*intval($forcefill);
     $src_rect_yoffset = ($height - $src_rect_height)/2*intval($forcefill);

     $thumb  = imagecreatetruecolor($th_width, $th_height);
     imagecopyresized($thumb, $source, 0, 0, $src_rect_xoffset, $src_rect_yoffset, $th_width, $th_height, $src_rect_width, $src_rect_height);

     imagejpeg($thumb,$destination);
   }
}

?>
Kod:
<?php

//Upload------------------------------------
if(isset( $submit ))
{
if ($_FILES['imagefile']['type'] == "image/jpeg"){
   copy ($_FILES['imagefile']['tmp_name'], "../images/".$_FILES['imagefile']['name'])
   or die ("Could not copy");
       echo "";
       echo "Image Name: ".$_FILES['imagefile']['name']."";
       echo "<br>Image Size: ".$_FILES['imagefile']['size']."";
       echo "<br>Image Type: ".$_FILES['imagefile']['type']."";
       echo "<br>Image Copy Done....<br>";
       }
         else {
           echo "<br><br>";
           echo "bad file type (".$_FILES['imagefile']['name'].")<br>";exit;
             }
//-----upload end

//------start thumbnailer

   $thumbsize=120;
   echo "Thumbnail Info: <br>
         1.Thumb defined size: - OK: $thumbsize<br>";
   $imgfile = "../images/$imagefile_name";//processed image
   echo "
         2.Image destination: - OK: $imgfile<br>";
   header('Content-type: image/jpeg');
   list($width, $height) = getimagesize($imgfile);
   echo "3.Image size - OK: W=$width x H=$height<br>";
   $imgratio=$width/$height;
   echo "3.Image ratio - OK: $imgratio<br>";
   if ($imgratio>1){
     $newwidth = $thumbsize;
     $newheight = $thumbsize/$imgratio;}
   else{
     $newheight = $thumbsize;
     $newwidth = $thumbsize*$imgratio;}
   echo "4.Thumb new size -OK: W=$newwidth x H=$newheight<br>";
   $thumb = ImageCreateTrueColor($newwidth,$newheight);
   echo "5.TrueColor - OK<br>";
   $source = imagecreatefromjpeg($imgfile);
   echo "6.From JPG - OK<br>";
   imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
   imagejpeg($thumb,"../images/thumbs/thumb_$imagefile_name",100);echo "7.Done... - OK<br>";
//-----------end--------------   
?>

or without any info, just resizing:

<?php
//------start thumbnailer
   $thumbsize=120;
   $imgfile = "../images/$imagefile_name";
   header('Content-type: image/jpeg');
   list($width, $height) = getimagesize($imgfile);
   $imgratio=$width/$height;
   if ($imgratio>1){
     $newwidth = $thumbsize;
     $newheight = $thumbsize/$imgratio;}
   else{
     $newheight = $thumbsize;
     $newwidth = $thumbsize*$imgratio;}
   $thumb = ImageCreateTrueColor($newwidth,$newheight);
   $source = imagecreatefromjpeg($imgfile);
   imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagejpeg($thumb,"../images/thumbs/thumb_$imagefile_name",100);
//-----------end-------------- 
?>
Kod:
<?php
function saveThumbnail($saveToDir, $imagePath, $imageName, $max_x, $max_y) {
   preg_match("'^(.*)\.(gif|jpe?g|png)$'i", $imageName, $ext);
   switch (strtolower($ext[2])) {
       case 'jpg' :
       case 'jpeg': $im  = imagecreatefromjpeg ($imagePath);
                     break;
       case 'gif' : $im  = imagecreatefromgif  ($imagePath);
                     break;
       case 'png' : $im  = imagecreatefrompng  ($imagePath);
                     break;
       default    : $stop = true;
                     break;
   }
   
   if (!isset($stop)) {
       $x = imagesx($im);
       $y = imagesy($im);
   
       if (($max_x/$max_y) < ($x/$y)) {
           $save = imagecreatetruecolor($x/($x/$max_x), $y/($x/$max_x));
       }
       else {
           $save = imagecreatetruecolor($x/($y/$max_y), $y/($y/$max_y));
       }
       imagecopyresized($save, $im, 0, 0, 0, 0, imagesx($save), imagesy($save), $x, $y);
       
       imagegif($save, "{$saveToDir}{$ext[1]}.gif");
       imagedestroy($im);
       imagedestroy($save);
   }
}
?>
Kod:
<?php
function resize($cur_dir, $cur_file, $newwidth, $output_dir)
{
   $dir_name = $cur_dir;
   $olddir = getcwd();
   $dir = opendir($dir_name);
   $filename = $cur_file;
   $format='';
   if(preg_match("/.jpg/i", "$filename"))
   {
       $format = 'image/jpeg';
   }
   if (preg_match("/.gif/i", "$filename"))
   {
       $format = 'image/gif';
   }
   if(preg_match("/.png/i", "$filename"))
   {
       $format = 'image/png';
   }
   if($format!='')
   {
       list($width, $height) = getimagesize($filename);
       $newheight=$height*$newwidth/$width;
       switch($format)
       {
           case 'image/jpeg':
           $source = imagecreatefromjpeg($filename);
           break;
           case 'image/gif';
           $source = imagecreatefromgif($filename);
           break;
           case 'image/png':
           $source = imagecreatefrompng($filename);
           break;
       }
       $thumb = imagecreatetruecolor($newwidth,$newheight);
       imagealphablending($thumb, false);
       $source = @imagecreatefromjpeg("$filename");
       imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
       $filename="$output_dir/$filename";
       @imagejpeg($thumb, $filename);
   }
}
?>
call this function using
<?
resize("./input folder", "picture_file_name", "width", "./output folder");
?>


Bunlar sadece bu konuda birkaç uygulama örneği. Benim PHP Kod Arşivinden aldım. Yalnış hatırlamıyorsam bu kodları ben zamanında php.net sitesinden almıştım.
Başa dön
Kullanıcının profilini görüntüle Özel mesaj gönder Yazarın web sitesini ziyaret et
Bu Site Google Adsense ile Gelir Elde Ediyor









Tarih: 2024-04-19, 21:43:09    Mesaj konusu: Forum Arası Reklamlar


Başa dön
Zulwarn
Mesaj: 100+
Mesaj: 100+





Kayıt: Mar 26, 2006
Mesajlar: 191
Konum: Http://Turkish-Hiphop.Net/html

MesajTarih: 2006-08-23, 21:50:58    Mesaj konusu: Alıntıyla Cevap Gönder

Ali0sman bunlari nasil kullaniyoruz & ne i$e yariyorlar dostum biraz aciklarsan cok sevinirim -

sürekli soru soruyorum ama kusura bakmayin yaffz yeni yeni ogreniyoruz anca ..

te$ekkürler~
Başa dön
Kullanıcının profilini görüntüle Özel mesaj gönder E-posta gönder Yazarın web sitesini ziyaret et AIM Adresi Yahoo Messenger MSN Messenger
Aliosman
Teknik Yönetici
Teknik Yönetici





Kayıt: Jul 20, 2002
Mesajlar: 3836
Konum: Balıkesir

MesajTarih: 2006-08-23, 21:54:02    Mesaj konusu: Alıntıyla Cevap Gönder

PHP ile ilgili uygulama yapanlara yardımcı olmak amacıyla yayınlıyorum. Yani PHP de belli bir seviyeye gelenlere yöneliktir ki zamanla herkes bu kodları anlar hale gelecektir.

PHP-Nuke için bu kodları nasıl uydurursunuz açıklamıyorum. Amacım php-nuke değil, kendi sistemlerimiz.
Başa dön
Kullanıcının profilini görüntüle Özel mesaj gönder Yazarın web sitesini ziyaret et
turkercan
Mesaj: 1+
Mesaj: 1+





Kayıt: Dec 16, 2004
Mesajlar: 30
Konum: trabzon

MesajTarih: 2007-02-11, 15:35:14    Mesaj konusu: Alıntıyla Cevap Gönder

İşime ayradı teşekkürler..
Başa dön
Kullanıcının profilini görüntüle Özel mesaj gönder
polibo06
Site Yöneticisi
Site Yöneticisi





Kayıt: Nov 01, 2006
Mesajlar: 2412
Konum: izmirimi özledim

MesajTarih: 2008-06-19, 20:51:18    Mesaj konusu: Alıntıyla Cevap Gönder

işte benim ustadım...yıl çoşmuş....yıl çoşmak üzere... Wink
Başa dön
Kullanıcının profilini görüntüle Özel mesaj gönder Yazarın web sitesini ziyaret et
Önceki mesajları göster:   
Bu forum kilitlendi: mesaj gönderemez, cevap yazamaz ya da başlıkları değiştiremezsiniz   Bu başlık kilitlendi: mesajları değiştiremez ya da cevap yazamazsınız    Netopsiyon Online Forum Ana Sayfa -> PHP -> PHP Kod Örnekleri Tüm zamanlar GMT + 3 Saat
1. sayfa (Toplam 1 sayfa)

 
Geçiş Yap:  
Bu forumda yeni başlıklar açamazsınız
Bu forumdaki başlıklara cevap veremezsiniz
Bu forumdaki mesajlarınızı değiştiremezsiniz
Bu forumdaki mesajlarınızı silemezsiniz
Bu forumdaki anketlerde oy kullanamazsınız

Benzer Konular

Başlık Yazar Forum Cevaplar Tarih
Yeni mesaj yok Site İndex'ine resim ekleme cuneytsonmez HTML Kod Örnekleri 6 2010-07-17, 01:02:43 Son Mesajı Görüntüle
Yeni mesaj yok Konu başlıkları boyutu avara1984 Php Nuke Sorunlarınız 1 2010-07-15, 23:09:54 Son Mesajı Görüntüle
Yeni mesaj yok Resim Göstermeme Sorunu DursunKaptan Php Nuke Sorunlarınız 2 2010-07-08, 10:12:34 Son Mesajı Görüntüle
Yeni mesaj yok asp resim galerisi scrpti lazım gergernur Diğer Diller 0 2010-07-05, 19:51:50 Son Mesajı Görüntüle
Yeni mesaj yok Forum konusuna resim ekleme. avara1984 Php Nuke Sorunlarınız 1 2010-07-04, 23:46:10 Son Mesajı Görüntüle

Copyright © 2002-2024 Netopsiyon Bilişim Teknolojileri San. Tic. Ltd.Şti. - Bütün hakları saklıdır!
Bu site Netopsiyon.com.tr Sunucularında Barındırılmaktadır.
Netopsiyon Bilişim Teknolojileri San. Tic. Ltd.Şti. Netopsiyon Copyright