Kullanımı basit fonksiyon içine müdehale etmeden çekilecek url, kaydedilecek klasör ve watermark grafiğini kullanabilirsin.
Resimlerin çekileceği klasöre chmod 777 uygulamak gerekebilir. (sunucu izinleri ile alakali.)
kendine ufak bir watermak png oluşturup kullanmaya başlayabilirsin.
<?php
function resimcekWaterMark($url, $dizin, $watermark, $yenisim = false) {
$path_parts = pathinfo($url);
if (!empty($yenisim)) {
$resimLoc = $dizin."/".$yenisim;
}
else {
$resimLoc = $dizin."/".time().substr(md5(rand()),0,10).".".$path_parts['extension'];
}
/** resim'i ftp'e kaydediyoruz **/
$chi = curl_init($url); //dosyayı burada alıyoruz kendi serverımıza
$fpi = fopen($resimLoc, "w"); //geçici klasöre dosyayı yazdırıyoruz
curl_setopt($chi, CURLOPT_FILE, $fpi);
curl_setopt($chi, CURLOPT_HEADER, 0);
curl_setopt($chi, CURLOPT_REFERER, "http://www.google.com/bot.html");
curl_setopt($chi, CURLOPT_CONNECTTIMEOUT, 40);
curl_setopt($chi, CURLOPT_TIMEOUT, 40);
curl_exec($chi);
curl_close($chi);
fclose($fpi);
/** watermark işlemleri **/
$img=imagecreatefromjpeg($resimLoc);
$img_width=imagesx($img);
$img_height=imagesy($img);
$watermark=imagecreatefrompng($watermark);
$watermark_width=imagesx($watermark);
$watermark_height=imagesy($watermark);
$image=imagecreatetruecolor($watermark_width, $watermark_height);
imagealphablending($image, false);
$dest_x=$img_width-$watermark_width-5;
$dest_y=$img_height-$watermark_height-5;
imagecopy($img, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height);
imagesavealpha($img, true);
if (imagejpeg($img, $resimLoc, 90)) {
return true;
}
else {
return false;
}
}
//kullanımı
if (resimcekWaterMark("http://www.ajansspor.com/resimv3/lebron_040314.jpg", "resimler", "watermark.png", "yeniresimadi.jpg")) { //resimurl, klasör, watermark, kaydedilecek isim
echo "tamamdir";
}
else {
echo "yapilamadi";
}
?>
buddy adlı üyeden alıntı:
mesajı görüntüle