GD help pls!!!
5 отговора
205 прегледа
GD help pls!!!
Napisah si tazi funkciika no neshto mi se byrka rabotata!
<?php
function mark_image($img){
$background = imagecreatefromjpeg($img);
$insert = imagecreatefromgif("mark.gif");
imagecolortransparent($insert,imagecolorexact($insert,255,0,255));
$insert_x = imagesx($insert);
$insert_y = imagesy($insert);
$size_back = getimagesize($img);
$size_insert = getimagesize("mark.gif");
$width = ($size_back[0]-$size_insert[0])-3;
$height = ($size_back[1]-$size_insert[1])-3;
imagecopymerge($background,$insert,$width,$height,0,0,$insert_x,$insert_y,100);
imagejpeg($background,"","75");
}
?>
Ako nqkoj moje da mi kaje zashto kato vzema fil-a i ako skripta ne e na pyrvi red mi pechata ieroglifi?
predpolagam che trqbva da se decode i probvah s base64_decode(); no nishto ne se poluchava nqkoj moje li da mi helpne po vyprosa...
P.S. Tova bi trqbvalo da pravi watermark na dadena kartinka.. i da go zapisva na server-a!
10x to all!
<?php
function mark_image($img){
$background = imagecreatefromjpeg($img);
$insert = imagecreatefromgif("mark.gif");
imagecolortransparent($insert,imagecolorexact($insert,255,0,255));
$insert_x = imagesx($insert);
$insert_y = imagesy($insert);
$size_back = getimagesize($img);
$size_insert = getimagesize("mark.gif");
$width = ($size_back[0]-$size_insert[0])-3;
$height = ($size_back[1]-$size_insert[1])-3;
imagecopymerge($background,$insert,$width,$height,0,0,$insert_x,$insert_y,100);
imagejpeg($background,"","75");
}
?>
Ako nqkoj moje da mi kaje zashto kato vzema fil-a i ako skripta ne e na pyrvi red mi pechata ieroglifi?
predpolagam che trqbva da se decode i probvah s base64_decode(); no nishto ne se poluchava nqkoj moje li da mi helpne po vyprosa...
P.S. Tova bi trqbvalo da pravi watermark na dadena kartinka.. i da go zapisva na server-a!
10x to all!
Re: GD help pls!!!
Tova s maimunite namirisva na nepravilno izprateni headeri.
Kak pishesh imageto na diska?
Kak pishesh imageto na diska?
Re: GD help pls!!!
май сорс дет е няма връзка с китайците, я виж тода което отваряш и следващия път давай инишъл и ризълт.
Иначе що ли имм усещане че се прави бъзик
-----------------------
гърбавия, ковчег ще го изправи
Иначе що ли имм усещане че се прави бъзик
-----------------------
гърбавия, ковчег ще го изправи
Re: GD help pls!!!
Щото се изпраща нещо преди Image контента, което не се интерпретира като картинка от браУсера :-)
Е тук нищо няма:[линк]
Е тук нищо няма:[линк]
Opravih se .. daje si drsnah i class!
Ako nqkoj ima nujda.. tova se poluchi dosta dobre..
Znachi moje da si pravish ramka na thumbnail-a i da si slagash nadpis ili neshto na realnata snimka.. i gi pravi dosta malki!
Eto source-a:
<?php
class EXTRA_GALLERY {
var $thumb_size = "75x75"; // Ex. 150x150 (in pixels)
var $thumb_frame = "./frame.gif"; // frame for thumbnail
var $watermark = "./mark.gif"; // watermark
var $source; // file for treatment
var $main_folder = "photos/"; // to store original image
var $thumb_folder = "photos/thumbs/"; // to store thumbnail image
var $max_file_size = "70000"; // max file size in Kb
var $available_ext = array(".jpeg",".jpg",".gif",".png"); // available extentions
var $make_thumbnail = "yes"; // yes or no
var $make_watermark = "yes"; // yes or no
// get extention of file
function get_extention($file){
$extention = strrchr($file,".");
return $extention;
}
// check available extention
function check_extention(){
$ext = $this->get_extention($this->source['name']);
foreach($this->available_ext as $key => $e){
$ex .= "$e ";
if($e == $ext){
return true;
}
}
echo "Your file extension is forbiden!
Available are: $ex";
return false;
}
// check file size
function check_size(){
if($this->max_file_size < $this->source['size']){
echo "Your file is bigger than ".$this->max_file_size." kb.";
return false;
}
return true;
}
// Initialize CREATE Function
function GD_create($file){
$ext = $this->get_extention($this->source['name']);
//if .gif make GD Function
if($ext == ".gif"){
$create = imagecreatefromgif($file);
}
//if .jpeg, .jpg make GD Function
elseif($ext == ".jpeg" || $ext == ".jpg"){
$create = imagecreatefromjpeg($file);
}
//if .png make GD Function
elseif($ext == ".png"){
$create = imagecreatefrompng($file);
}
return $create;
}
// Initialize IMAGE Function
function GD_image($file,$folder,$q=75){
$ext = $this->get_extention($this->source['name']);
//if .gif
if($ext == ".gif"){
imagegif($file,$folder);
}
//if .jpeg, .jpg
elseif($ext == ".jpeg" || $ext == ".jpg"){
imagejpeg($file,$folder,$q);
}
//if .png
elseif($ext == ".png"){
imagepng($file,$folder);
}
}
// make frame on thumbnail
function make_thumbnail(){
if($this->make_thumbnail == "yes"){
$num = rand(0, 9999999);
$ext = $this->get_extention($this->source['name']);
$temp_file = "TEMP_".$num.$ext;
$temp_bg = "NEW_".$num.$ext;
// make thumbnail
$temporary = $this->thumb_folder.$temp_file;
$temp_wall = $this->thumb_folder.$temp_bg;
$size = $this->thumb_size;
// make thumbnail via IMAGE MAGIC SOFTWARE
exec("/usr/bin/convert -size $size ".$this->source['tmp_name']." -resize $size +profile \"*\" $temporary");
$wall = imagecreate(75,75);
$tmp = $this->GD_create($temporary);
$insert_tx = imagesx($tmp);
$insert_ty = imagesy($tmp);
imagecopymerge($wall,$tmp,0,0,0,0,75,75,100);
$this->GD_image($wall,$this->thumb_folder.$temp_bg,100);
imagedestroy($wall);
$background = $this->GD_create($temp_wall);
// create from frame
$insert = imagecreatefromgif($this->thumb_frame);
$insert_x = imagesx($insert);
$insert_y = imagesy($insert);
imagecopymerge($background,$insert,0,0,0,0,$insert_x,$insert_y,100);
$this->GD_image($background,$this->thumb_folder.$this->source['name'],80);
imagedestroy($background);
unlink($temporary);
unlink($temp_wall);
}
}
// mark photo with watermark
function make_watermark(){
if($this->make_watermark == "yes"){
$background = $this->GD_create($this->source['tmp_name']);
$insert = imagecreatefromgif($this->watermark);
$insert_x = imagesx($insert);
$insert_y = imagesy($insert);
$size_back = getimagesize($this->source['tmp_name']);
$size_insert = getimagesize($this->watermark);
$width = ($size_back[0]-$size_insert[0])-1;
$height = ($size_back[1]-$size_insert[1])-1;
imagecopymerge($background,$insert,$width,$height,0,0,$insert_x,$insert_y,100);
$this->GD_image($background,$this->main_folder.$this->source['name'],75);
imagedestroy($background);
}
else{
if(!@copy($this->source['tmp_name'],$this->main_folder.$this->source['name'])){
echo "Can't write into server!";
}
}
}
}// END CLASS PHOTO
// Vikash class-a
if($HTTP_POST_FILES['photo']['size'] >0){
$photo = new EXTRA_GALLERY;
// start class settings
$photo->source = $HTTP_POST_FILES[photo];
$photo->make_thumbnail = "yes";
$photo->make_watermark = "yes";
// this lines are absolutely required
if($photo->check_extention() && $photo->check_size()){
$photo->make_thumbnail();
$photo->make_watermark();
}
// end class settings
}
?>
Znachi moje da si pravish ramka na thumbnail-a i da si slagash nadpis ili neshto na realnata snimka.. i gi pravi dosta malki!
Eto source-a:
<?php
class EXTRA_GALLERY {
var $thumb_size = "75x75"; // Ex. 150x150 (in pixels)
var $thumb_frame = "./frame.gif"; // frame for thumbnail
var $watermark = "./mark.gif"; // watermark
var $source; // file for treatment
var $main_folder = "photos/"; // to store original image
var $thumb_folder = "photos/thumbs/"; // to store thumbnail image
var $max_file_size = "70000"; // max file size in Kb
var $available_ext = array(".jpeg",".jpg",".gif",".png"); // available extentions
var $make_thumbnail = "yes"; // yes or no
var $make_watermark = "yes"; // yes or no
// get extention of file
function get_extention($file){
$extention = strrchr($file,".");
return $extention;
}
// check available extention
function check_extention(){
$ext = $this->get_extention($this->source['name']);
foreach($this->available_ext as $key => $e){
$ex .= "$e ";
if($e == $ext){
return true;
}
}
echo "Your file extension is forbiden!
Available are: $ex";
return false;
}
// check file size
function check_size(){
if($this->max_file_size < $this->source['size']){
echo "Your file is bigger than ".$this->max_file_size." kb.";
return false;
}
return true;
}
// Initialize CREATE Function
function GD_create($file){
$ext = $this->get_extention($this->source['name']);
//if .gif make GD Function
if($ext == ".gif"){
$create = imagecreatefromgif($file);
}
//if .jpeg, .jpg make GD Function
elseif($ext == ".jpeg" || $ext == ".jpg"){
$create = imagecreatefromjpeg($file);
}
//if .png make GD Function
elseif($ext == ".png"){
$create = imagecreatefrompng($file);
}
return $create;
}
// Initialize IMAGE Function
function GD_image($file,$folder,$q=75){
$ext = $this->get_extention($this->source['name']);
//if .gif
if($ext == ".gif"){
imagegif($file,$folder);
}
//if .jpeg, .jpg
elseif($ext == ".jpeg" || $ext == ".jpg"){
imagejpeg($file,$folder,$q);
}
//if .png
elseif($ext == ".png"){
imagepng($file,$folder);
}
}
// make frame on thumbnail
function make_thumbnail(){
if($this->make_thumbnail == "yes"){
$num = rand(0, 9999999);
$ext = $this->get_extention($this->source['name']);
$temp_file = "TEMP_".$num.$ext;
$temp_bg = "NEW_".$num.$ext;
// make thumbnail
$temporary = $this->thumb_folder.$temp_file;
$temp_wall = $this->thumb_folder.$temp_bg;
$size = $this->thumb_size;
// make thumbnail via IMAGE MAGIC SOFTWARE
exec("/usr/bin/convert -size $size ".$this->source['tmp_name']." -resize $size +profile \"*\" $temporary");
$wall = imagecreate(75,75);
$tmp = $this->GD_create($temporary);
$insert_tx = imagesx($tmp);
$insert_ty = imagesy($tmp);
imagecopymerge($wall,$tmp,0,0,0,0,75,75,100);
$this->GD_image($wall,$this->thumb_folder.$temp_bg,100);
imagedestroy($wall);
$background = $this->GD_create($temp_wall);
// create from frame
$insert = imagecreatefromgif($this->thumb_frame);
$insert_x = imagesx($insert);
$insert_y = imagesy($insert);
imagecopymerge($background,$insert,0,0,0,0,$insert_x,$insert_y,100);
$this->GD_image($background,$this->thumb_folder.$this->source['name'],80);
imagedestroy($background);
unlink($temporary);
unlink($temp_wall);
}
}
// mark photo with watermark
function make_watermark(){
if($this->make_watermark == "yes"){
$background = $this->GD_create($this->source['tmp_name']);
$insert = imagecreatefromgif($this->watermark);
$insert_x = imagesx($insert);
$insert_y = imagesy($insert);
$size_back = getimagesize($this->source['tmp_name']);
$size_insert = getimagesize($this->watermark);
$width = ($size_back[0]-$size_insert[0])-1;
$height = ($size_back[1]-$size_insert[1])-1;
imagecopymerge($background,$insert,$width,$height,0,0,$insert_x,$insert_y,100);
$this->GD_image($background,$this->main_folder.$this->source['name'],75);
imagedestroy($background);
}
else{
if(!@copy($this->source['tmp_name'],$this->main_folder.$this->source['name'])){
echo "Can't write into server!";
}
}
}
}// END CLASS PHOTO
// Vikash class-a
if($HTTP_POST_FILES['photo']['size'] >0){
$photo = new EXTRA_GALLERY;
// start class settings
$photo->source = $HTTP_POST_FILES[photo];
$photo->make_thumbnail = "yes";
$photo->make_watermark = "yes";
// this lines are absolutely required
if($photo->check_extention() && $photo->check_size()){
$photo->make_thumbnail();
$photo->make_watermark();
}
// end class settings
}
?>
Re: Opravih se .. daje si drsnah i class!
Човека е фен на:
echo eregi_replace("-", "", $neshto);
а иначе класа е ОК само дето до вчера $this->source му беше непонятно като конструкция!


echo eregi_replace("-", "", $neshto);
а иначе класа е ОК само дето до вчера $this->source му беше непонятно като конструкция!