İyinet'e Hoşgeldiniz!

Türkiye'nin En Eski Webmaster Forum'una Hemen Kayıt Olun!

Kayıt Ol!

resim upload ederken optimize etmek

paskalaki

0
İyinet Üyesi
Katılım
31 Mayıs 2008
Mesajlar
92
Reaction score
0
aşağıdaki kodlarım çalışıyor fakat buna optimize vede upload ederken üzerine yazı eklemek istedim
formdan gelen input name resim1
optimize derken fotoğraf makinesiyle çekilen resimlerin hem kb boyutu hemde alan olarak boyutunu ufaltarak yapmak istiyorum
Kod:
<?php
include("../ayar/ayar.php");
mysql_query("SET NAMES 'latin5'"); 
$rasgele1 = md5(microtime());
$resimek1 = $rasgele1.".jpg";
$resim1 = $_FILES['resim1']['name'];
if($_FILES['resim1']['name'] != "" )
{
$resimek1 = md5(microtime()).".jpg";
}
else
{
$resimek1 = "resimyok.jpg";
}
{
$sql = "insert into emlak_bilgileri_db (resim1)
values ('$resimek1')";
$kayit = mysql_query($sql);
}
if (isset ($kayit))
{
?>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1254">
<meta http-equiv="content-type" content="text/html;charset=ISO-8859-9">
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" bgcolor="#EAEDF4" style="text-align: center">
<p><b><font color="#0099FF">İlan Kaydınız Yapılmıştır</font></b>
<?php
$id= mysql_insert_id(); 
echo "İlan numaranız        :    $id<br>";
}
else 
{
echo "resim Kayıt Başarısız";
}
$uploadir = "../emlak_resimler/";
mkdir($uploadir."".$id, 0777);
$uploaddir = "../emlak_resimler/$id";
copy("../web_resimler/resimyok.jpg","../emlak_resimler/$id/resimyok.jpg");
if(is_uploaded_file($_FILES['resim1']['tmp_name']))
{
move_uploaded_file($_FILES['resim1']['tmp_name'],$uploaddir.'/'.$resimek1);
}
?>
 

serki

0
İyinet Üyesi
Katılım
5 Ocak 2005
Mesajlar
200
Reaction score
0
Bence kesinlikle resmin orjinalini (veya optimize edilmiş halini) yazı vb. ekleyerek bozma. Resmi gösterirken üzerine watermark ile yazı yazmak daha mantıklı. Bu şekilde resimleri başka sitelerin vs. için her zaman kullanabilirsin. Bkz: Watermark Images on the Fly in PHP

Ototmatik resim küçültme işlemleri için de thumbnailer class kullanabilirsin
 

paskalaki

0
İyinet Üyesi
Katılım
31 Mayıs 2008
Mesajlar
92
Reaction score
0
bu kod var fakat bastığı resim kaliteli değil ve siyah font brakıyor bir incelermisiniz hem yazı yazmak için hemde upload ederken resim kb boyutunu küçültüyor


ims.php
Kod:
<?php

// -----------------------------------------------------------------------------------
// * Prevents image manipulating attacks
// * @ Coded By Yns - yns.zaxaz.com - <[email protected]>
// -----------------------------------------------------------------------------------

class control {
	var $image;
	var $site_sign = "buraya yazı gelecek";
	var $type;
	var $width  = 100;
	var $height = 80;
	var $sign = 1; // 1 enabled, 0 disabled.
	var $quality = 99; // optimal 75 , [0-100] 
	
	// Find image's type
      	function kontrol($dosya,$tur) {
            	if($tur == 'image/pjpeg' || $tur =='image/jpeg') {
         		$this->image    = @imagecreatefromjpeg($dosya);
			$this->type = "jpg";
      		} elseif($tur == 'image/gif') {
         		$this->image = @imagecreatefromgif($dosya);
			$this->type = "gif";
      		} elseif($tur == 'image/png' || $tur =='image/x-png') {
         		$this->image = @imagecreatefrompng($dosya);
			$this->type = "png";
      		} else {
         		die("Sadece .JPG , .PNG , .GIF uzantili dosyalar kabul edilmekte..");
      		} 
    	}    
		
		// RE-create the image	
		function yukle($dosya,$dizin,$isim) {
		$width  = @imagesx($this->image);
        $height = @imagesy($this->image);
		
		if($this->sign == 1) {
			// control for too small images
			if($width > $this->width && $height > $this->height) {
				// Imza grafigini olustur				
				$imza = imagecreatetruecolor($this->width,$this->height);
				$yazi_rengi  = imagecolorallocate($imza, 255, 255, 255);
				imagestring($imza, 1, 0, 0, $this->site_sign, $yazi_rengi);
			
			}	
		
			// copy sign to image
			if(isset($imza)) {
				imagecopy($this->image, $imza, imagesx($this->image)-imagesx($imza)-1, imagesy($this->image)-imagesy($imza)-1, 0, 0, imagesx($this->image), imagesy($imza));
			}
		}
		// Routine controls ( you can cancel this..)
		if(substr(sprintf('%o', fileperms($dizin)), -4) != '777') die("$dizin directory perms aren't enough.Should be 777.");
		if(file_exists("$dizin/$isim")) die("This image has already uploaded.");
		
		// Save the image with suitable function
		if($this->type == 'jpg') { 
			@imagejpeg($this->image,"$dizin"."/"."$isim",$this->quality) or die("Gecerli bir .JPG dosyasi degil.");
		} elseif($this->type == 'gif') {
			@imagegif ($this->image,"$dizin"."/"."$isim",$this->quality) or die("Gecerli bir GIF dosyasi degil.");
		} elseif($this->type == 'png') {
			@imagepng($this->image,"$dizin"."/"."$isim",$this->quality) or die("Gecerli bir PNG dosyasi degil.");
		}

		// Flush memory
		@imagedestroy($this->image);
		}
		
} 

?>

formu

Kod:
<?php
include'ims.php';
if(!empty($_FILES)) {
$kontrol = new control();
$kontrol->kontrol($_FILES["file"]["tmp_name"],$_FILES["file"]["type"]);
$kontrol->yukle($_FILES["file"]["tmp_name"],"test",$_FILES["file"]["name"]);
echo("File uploaded...");
}
?> 

<form method="post" enctype="multipart/form-data">
  File: <input name="file" type="file">
  <input type="submit" value="Send">
</form>
 

Türkiye’nin ilk webmaster forum sitesi iyinet.com'da forum üyeleri tarafından yapılan tüm paylaşımlardan; Türk Ceza Kanunu’nun 20. Maddesinin, 5651 Sayılı Kanununun 4. maddesinin 2. fıkrasına göre, paylaşım yapan üyeler sorumludur.

Backlink ve Tanıtım Yazısı için iletişime geçmek için Skype Adresimiz: .cid.1580508955483fe5

seo ajansı , sosyal medya yönetimi
Üst