Toplam Üye:
32638
Aktif Üye:
0
Aktif Ziyaretçi:
976
acil web sayfa boyutu ner ..(5902 okuma, 3 yanıt) uye adina gore veri cekme ..(5090 okuma, 1 yanıt) Ajax vb. Manşet Scripti? ..(5958 okuma, 2 yanıt) Random banner nasıl yapar ..(4606 okuma, 1 yanıt) Veritabanına Alan Eklemek ..(4026 okuma, 0 yanıt) downlaod sitesi için hazı ..(8449 okuma, 7 yanıt) popup sayfa lütfen yardım ..(5107 okuma, 0 yanıt) youtube indirici getten g ..(6566 okuma, 2 yanıt) Hicri Takvime göre Tarih ..(3611 okuma, 0 yanıt) Telefon Rehberi ..(4103 okuma, 0 yanıt) dosya indirirken 10 saniy ..(4540 okuma, 2 yanıt) switch komutu çalıştırama ..(3964 okuma, 0 yanıt) Bu kodun neresine rel=nof ..(8328 okuma, 8 yanıt) include ve require kod ha ..(8694 okuma, 8 yanıt) Remote File İnclude - RFI ..(6744 okuma, 4 yanıt) php de form dan gönderile ..(7380 okuma, 5 yanıt) Otomatik Şifre Üretimi ..(4719 okuma, 1 yanıt) PHP ile resim boyutu ayar ..(8041 okuma, 4 yanıt) Rastgele Şifre Üretmek ..(4928 okuma, 2 yanıt) klasördeki resimleri php ..(10526 okuma, 9 yanıt) PHP Bilgisini Öğrenelim ..(13300 okuma, 12 yanıt) Php Ekşin - Php'ye Giriş ..(6623 okuma, 4 yanıt) firefox harici kişilere & ..(4181 okuma, 0 yanıt) BB-Code Fonksiyonu ..(5450 okuma, 2 yanıt) PHP ile PNG resim oluştur ..(6025 okuma, 2 yanıt) Rastgele Şifre Üretmek ..(8103 okuma, 5 yanıt) Dizin okuma,dosyalarıdizm ..(4175 okuma, 0 yanıt) PHP'nin Yapı Taşları ..(4531 okuma, 0 yanıt) Php ye giriş ..(4870 okuma, 0 yanıt) Google gibi Otomatik dil ..(10931 okuma, 11 yanıt)
Netopsiyon Online: Forums
Netopsiyon Online :: Başlık görüntüleniyor - PHP ile resim boyutu ayarlama
Önceki başlık :: Sonraki başlık
Yazar
Mesaj
Aliosman Teknik Yönetici
Kayıt: Jul 20, 2002 Mesajlar: 3836 Konum: Balıkesir
Tarih: 2006-08-23, 21:47:58 Mesaj konusu: PHP ile resim boyutu ayarlama
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
Bu Site Google Adsense ile Gelir Elde Ediyor
Tarih: 2025-11-03, 07:01:46 Mesaj konusu: Forum Arası Reklamlar
Başa dön
Zulwarn Mesaj: 100+
Kayıt: Mar 26, 2006 Mesajlar: 191 Konum: Http://Turkish-Hiphop.Net/html
Tarih: 2006-08-23, 21:50:58 Mesaj konusu:
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
Aliosman Teknik Yönetici
Kayıt: Jul 20, 2002 Mesajlar: 3836 Konum: Balıkesir
Tarih: 2006-08-23, 21:54:02 Mesaj konusu:
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
turkercan Mesaj: 1+
Kayıt: Dec 16, 2004 Mesajlar: 30 Konum: trabzon
Tarih: 2007-02-11, 15:35:14 Mesaj konusu:
İşime ayradı teşekkürler..
Başa dön
polibo06 Site Yöneticisi
Kayıt: Nov 01, 2006 Mesajlar: 2412 Konum: izmirimi özledim
Tarih: 2008-06-19, 20:51:18 Mesaj konusu:
işte benim ustadım...yıl çoşmuş....yıl çoşmak üzere...
Başa dön
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