Resimlerin Üzerine Yazı Yazmak
Yazan: ayhan,DigerTags/Kelimeler: filigran, php filigran, php resim, php resim boyutlandırma, php resim işleme, php watermark, resim üstüne yazı, resim koruma, Resimlerin Üzerine Yazı Yazmak, watermark
benim tavsiyem:
1- yuklenen orjinal resmi ayri bir dizinde sakla.
2- orjinal resim ile filigran.png , 2 resmi php ile üst üste getir. boylece basit bir yazi degil logo bile çakabilirsin.
3- oluşan yeni resmi kaydet.
filigran.png transparan , şeffaflığı %15 olan bir resim olsun ki aşırı rahatsiz etmesin.
bu benim yazdiğim ve kullandigim fonksiyonum :
-
function resim_yukle($kaynak,$hedef,$h,$w,$kalite=90,$filigran=0,$temsili=0,$getimagesize=0) {
-
if ($getimagesize==0) {
-
}
-
else {
-
$image_info = $getimagesize;
-
}
-
-
if($image_info['mime'] == 'image/jpg' || $image_info['mime']=='image/jpeg'|| $image_info['mime']=='image/pjpeg') {
-
$srcimg=imagecreatefromjpeg($kaynak);
-
}
-
elseif($image_info['mime'] == 'image/png'|| $image_info['mime'] == 'image/x-png') {
-
$srcimg=imagecreatefrompng($kaynak);
-
}
-
elseif($image_info['mime'] == 'image/gif') {
-
$srcimg=imagecreatefromgif($kaynak);
-
}
-
-
# orjinal wd ,hi
-
$o_wd = imagesx($srcimg) ;
-
$o_ht = imagesy($srcimg) ;
-
-
# hedef resim
-
$t_im = imagecreatetruecolor($w,$h);
-
-
$white = imagecolorallocate($t_im, 255, 255, 255);
-
imagefilledrectangle($t_im, 0, 0, $w, $h, $white);
-
-
if($o_wd>$o_ht) {
-
# resim yatik
-
$new_width = $w;
-
$new_height = ($o_ht*$new_width)/$o_wd;
-
}
-
elseif($o_wd<$o_ht || $o_wd==$o_ht) {
-
# resim dik
-
$new_height = $h;
-
$new_width = ($o_wd*$new_height)/$o_ht;
-
}
-
-
# eger orjinal resim hedef boyuttan kucuk ise buyutunce bozuluyor, buyutme!
-
if( ($o_wd<$w && $o_ht<$h)) {
-
imagecopyresampled($t_im, $srcimg, ($w-$o_wd)/2, ($h-$o_ht)/2, 0, 0,$o_wd,$o_ht, $o_wd, $o_ht);
-
}
-
else {
-
imagecopyresampled($t_im, $srcimg, ($w-$new_width)/2, ($h-$new_height)/2, 0, 0,$new_width,$new_height, $o_wd, $o_ht);
-
}
-
-
# üzerine filigran yazılacak mı?
-
if($filigran==1) {
-
$logo_file="/images/filigran.png";
-
$img_logo = imagecreatefrompng($logo_file);
-
$sx = imagesx($img_logo);
-
$sy = imagesy($img_logo);
-
}
-
-
# üzerine "Temsili Fotoğraf" yazılacak mı?
-
if($temsili==1) {
-
# yada baska bir yazi olabilir
-
$yazi=" Temsili Fotoğraf ";
-
//$font=2;
-
$font_file="/monofont.ttf";
-
$yer_x=110;
-
$yer_y=15;
-
-
$bg = imagecolorallocate($t_im, 255, 255, 255);
-
$textcolor = imagecolorallocate($t_im, 0, 0, 0);
-
ImageFilledRectangle($t_im, $w-$yer_x, $h-$yer_y-10, ($w-$yer_x)+88, ($h-$yer_y)+1, $bg);
-
imagettftext($t_im, 9, 0, $w-$yer_x, $h-$yer_y, $textcolor, $font_file, $yazi);
-
//imagestring($t_im, $font, $w-$yer_x, $h-$yer_y, $yazi, $textcolor);
-
}
-
-
if($image_info['mime'] == 'image/jpg' || $image_info['mime']=='image/jpeg'|| $image_info['mime']=='image/pjpeg') {
-
imagejpeg($t_im,$hedef,$kalite);
-
}
-
elseif($image_info['mime'] == 'image/png'|| $image_info['mime'] == 'image/x-png') {
-
imagepng($t_im,$hedef);
-
}
-
elseif($image_info['mime'] == 'image/gif') {
-
imagegif($t_im,$hedef);
-
}
-
imagedestroy($t_im);
-
}
Kullanım şekli:
resmi 90 kalitede , filigranli , 800x600 yap
-
$dizin = "/resimler/";
-
$yeniresim=$_FILES['resim_link'];
-
-
$userfile_tmp = $yeniresim['tmp_name'];
-
$userfile_size = $yeniresim['size'];
-
$userfile_type = $yeniresim['type'];
-
-
resim_yukle($userfile_tmp,$dizin.$userfile_name,600,800,90,1,$getimagesize);
100x100 thumbnail olarak başka dizine kopyala:
-
resim_yukle($userfile_tmp,$dizin."tn/".$userfile_name,100,100,90,0,$getimagesize);
Entries (RSS)