HoaXed Skrevet 26. oktober 2007 Del Skrevet 26. oktober 2007 Heisann, jeg har nå MG2 bildegalleriet men ønsker å vannmerke bildene som jeg får ut derfra. MG2 laster opp bildene på følgende måte; http://norskwebforum.no/pastebin/9827 Problemet er at jeg rett og slett ikke klarer å implinere riktige kode for å ordne opp med problemet; Jeg har prøvd følgende; <?php header('content-type: image/jpeg'); $watermark = imagecreatefrompng('watermark.png'); $watermark_width = imagesx($watermark); $watermark_height = imagesy($watermark); $image = imagecreatetruecolor($watermark_width, $watermark_height); $image = imagecreatefromjpeg($thumbbilde); $size = getimagesize($thumbbilde); $dest_x = $size[0] - $watermark_width - 5; $dest_y = $size[1] - $watermark_height - 5; imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100); imagejpeg($image); imagedestroy($image); imagedestroy($watermark); ?> Den vil ikke fungere, her har jeg latt MG2 først lage bildet mittbilde_thumb.jpg og hentet dette inn som en variabel $thumbbilde over. Den nekter å fungere. Jeg fant alikevell en annen muilighet noe med klasser som forøvrig så veldig enkelt ut her; http://www.litewebsite.com/?c=19 Men jeg aner ikke hvordan klasser fungerer; skal klassekoden ligge i en egen fil og så skal jeg ta $stamp = new LiteStamp('original.jpg', 'stamp.jpg', 'stamp_'); $stamp->stampPicture(); og kjøre denne! Takk for all hjelp Lenke til kommentar
Gjest Slettet+142 Skrevet 26. oktober 2007 Del Skrevet 26. oktober 2007 Du må inkludere LiteStamp sin kode, ja <?php include "fil_som_inneholder_litestamp_klassen.php"; // Erstatt $stamp = new LiteStamp('original.jpg', 'stamp.jpg', 'stamp_'); $stamp->stampPicture(); ?> LiteStamp-klassen Lenke til kommentar
HoaXed Skrevet 28. oktober 2007 Forfatter Del Skrevet 28. oktober 2007 Hmm. Prøvd enda mer og fant et script jeg kunne modifisere som jeg fikk til. Her kunne jeg lagre bildene og slike ting i tilleg. MEn jeg ønsker å vise bildene med vannmerke uten å lagre de. Da kan jeg bruke følgende kode; <?php // The image should be located in a non public directory $image_location = 'path/to/image/file/imagename.ext'; // Locate the watermark file wherever you choose (remember PNG format) $watermark_location = 'path/to/watermark.png'; // Include the watermarking function file require_once($_SERVER['DOCUMENT_ROOT'] . '/function_watermark.php'); // Watermark the image and send it to the browser watermark($image_location, $watermark_location); ?> Dette fungerer jo. Men jeg kan så enormt lite om dette området så aner ikke hvordan jeg skal få bildet printet ut. Jeg får bare en haug med uf. kode over hele siden. Hvordan skal jeg få bildet til å skrives ut? Lenke til kommentar
Gjest Slettet+142 Skrevet 28. oktober 2007 Del Skrevet 28. oktober 2007 Kan du vise oss innholdet i function_watermark.php? Vi kan jo ikke hjelpe når vi ikke får se watermark()-funksjonen...tror jeg Lenke til kommentar
HoaXed Skrevet 29. oktober 2007 Forfatter Del Skrevet 29. oktober 2007 (endret) Kan du vise oss innholdet i function_watermark.php?Vi kan jo ikke hjelpe når vi ikke får se watermark()-funksjonen...tror jeg Jaok. Etter mye lesing får jeg i alle fall til med litt modifisering å lagre selve filen! Men her er functions, hadde vært glimrende hvis jeg hadde fått til å ikke lagre, bare vise! http://norskwebforum.no/pastebin/9844 Gratulerer med gullet forresten! Hilsen FFK Endret 29. oktober 2007 av HoaXed Lenke til kommentar
Gjest Slettet+142 Skrevet 29. oktober 2007 Del Skrevet 29. oktober 2007 Fjern paramter#2 på linje 107, 111 og 115, så vil ikke filen lagres, bare vises Gratulerer med gullet forresten! Hilsen FFK Takk Var tungt å stå opp idag Lenke til kommentar
Gjest Slettet+142 Skrevet 29. oktober 2007 Del Skrevet 29. oktober 2007 <?php // NOTE: class is experimental // Copyright (c) 2006, Simon Jansson <http://www.litewebsite.com> all rights reserved. // License <http://litewebsite.com/license_BSD.html> //liteStamp::GDversion(); //$stamp = new LiteStamp('originalImage.jpg', 'stampImage.jpg', 'stamp_'); //$stamp->stampPicture(); class LiteStamp{ // class variables private $fileHandle = null; private $newPictureName = null; private $pictureInfo = null; private $pictureName = null; private $prefix = null; private $stampInfo = null; private $stampName = null; private $stampXpos = null; private $stampYpos = null; private $savetofile = true; function __construct($picture, $stamp, $savefile=true, $prefix = 'stamp_'){ $this->pictureName = $picture; // original picture to place stamp/watermark on $this->stampName = $stamp; // stamp/watermark picture if($savefile){ $this->prefix = $prefix; // prefix of new stamped picture }else{ $this->savetofile = false; } }// end of construct public static function GDversion(){ // GD 2.0.28 or newer is recommended version to use // http://www.php.net/manual/en/function.gd-info.php var_dump(gd_info()); // dump information about your GD version return true; }// end of GDversion private function openImage($fileName, $type){ // open picture with correct image function. Add more types if needed. // GIF: http://php.net/manual/en/function.imagecreatefromgif.php // JPG/JPEG: http://php.net/manual/en/function.imagecreatefromjpeg.php // PNG: http://php.net/manual/en/function.imagecreatefrompng.php switch ($type){ case 1: // GIF $this->fileHandle = imagecreatefromgif($fileName); break;// case 1 case 2: // JPG/JPEG $this->fileHandle = imagecreatefromjpeg($fileName); break;// case 2 case 3: // PNG $this->fileHandle = imagecreatefrompng($fileName); break;// case 3 default: die('Unsupported filetype: '.$fileName); } return $this->fileHandle; }// end of openImage public function getImagetype(){ if($this->pictureInfo==null) $this->pictureInfo = getimagesize($this->pictureName) or die('Error getting picture info. Double check file path.'); return image_type_to_mime_type( $this->pictureInfo[2] ); } public function stampPicture(){ // get picture info such as width, height and extension // http://php.net/manual/en/function.getimagesize.php $this->pictureInfo = getimagesize($this->pictureName) or die('Error getting picture info. Double check file path.'); $this->stampInfo = getimagesize($this->stampName) or die('Error getting stamp info. Double check file path.'); // open images with class method openImage() $this->pictureFile = $this->openImage($this->pictureName, $this->pictureInfo[2]); $this->stampFile = $this->openImage($this->stampName, $this->stampInfo[2]); // position the stamp in the lower right corner $this->stampXpos = $this->pictureInfo[0] - $this->stampInfo[0] - 15; // width - width - margin $this->stampYpos = $this->pictureInfo[1] - $this->stampInfo[1] - 15; // height - height - margin // set a new name for the stamped picture and keep the original picture intact $this->newPictureName = $this->prefix.$this->pictureName; // alpha blending: http://php.net/manual/en/function.imagealphablending.php imagealphablending($this->pictureFile, true); // merge the two images: http://php.net/manual/en/function.imagecopymerge.php imagecopymerge($this->pictureFile, $this->stampFile, $this->stampXpos, $this->stampYpos, 0, 0, $this->stampInfo[0], $this->stampInfo[1], 100); if($this->savetofile){ // output the stamped image as GIF, JPG/JPEG or PNG. Add more types if needed. // default type is the same as the original file // GIF: http://php.net/manual/en/function.imagegif.php // JPG/JPEG: http://php.net/manual/en/function.imagejpeg.php // PNG: http://php.net/manual/en/function.imagepng.php switch ($this->pictureInfo[2]){ case 1: // GIF if($this->savetofile) imagegif($this->pictureFile, $this->newPictureName); else imagegif($this->pictureFile); break;// case 1 case 2:// JPG/JPEG if($this->savetofile) imagejpeg($this->pictureFile, $this->newPictureName); else imagejpeg($this->pictureFile); break;// case 2 case 3: // PNG if($this->savetofile) imagepng($this->pictureFile, $this->newPictureName); else imagepng($this->pictureFile); break;// case 3 default: die('Unsupported filetype: '.$fileName); } }elseif(!$this->savetofile && in_array($this->pictureInfo[2], array(1, 2, 3))){ //Return type will be image/jpeg if $this->savetofile is false imagejpeg($this->pictureFile); }else{ die('Unsupported filetype: '.$fileName); } return true; }// end of stampPicture function destruct(){ unset($fileHandle, $newPictureName, $pictureInfo, $pictureName, $prefix, $stampInfo, $stampName, $stampXpos, $stampYpos); }// end of destruct }// end of class ?> Der har jeg fikset klassen til deg Nå kan du kjøre f.eks denne koden: <?php $wm = new LiteStamp("bilde.jpg", "watermark.jpg", false); header("Content-Type: ".$wm->getImagetype()); $wm->stampPicture(); ?> Jeg håper i alle fall det Lenke til kommentar
HoaXed Skrevet 29. oktober 2007 Forfatter Del Skrevet 29. oktober 2007 <?php // NOTE: class is experimental // Copyright (c) 2006, Simon Jansson <http://www.litewebsite.com> all rights reserved. // License <http://litewebsite.com/license_BSD.html> //liteStamp::GDversion(); //$stamp = new LiteStamp('originalImage.jpg', 'stampImage.jpg', 'stamp_'); //$stamp->stampPicture(); class LiteStamp{ // class variables private $fileHandle = null; private $newPictureName = null; private $pictureInfo = null; private $pictureName = null; private $prefix = null; private $stampInfo = null; private $stampName = null; private $stampXpos = null; private $stampYpos = null; private $savetofile = true; function __construct($picture, $stamp, $savefile=true, $prefix = 'stamp_'){ $this->pictureName = $picture; // original picture to place stamp/watermark on $this->stampName = $stamp; // stamp/watermark picture if($savefile){ $this->prefix = $prefix; // prefix of new stamped picture }else{ $this->savetofile = false; } }// end of construct public static function GDversion(){ // GD 2.0.28 or newer is recommended version to use // http://www.php.net/manual/en/function.gd-info.php var_dump(gd_info()); // dump information about your GD version return true; }// end of GDversion private function openImage($fileName, $type){ // open picture with correct image function. Add more types if needed. // GIF: http://php.net/manual/en/function.imagecreatefromgif.php // JPG/JPEG: http://php.net/manual/en/function.imagecreatefromjpeg.php // PNG: http://php.net/manual/en/function.imagecreatefrompng.php switch ($type){ case 1: // GIF $this->fileHandle = imagecreatefromgif($fileName); break;// case 1 case 2: // JPG/JPEG $this->fileHandle = imagecreatefromjpeg($fileName); break;// case 2 case 3: // PNG $this->fileHandle = imagecreatefrompng($fileName); break;// case 3 default: die('Unsupported filetype: '.$fileName); } return $this->fileHandle; }// end of openImage public function getImagetype(){ if($this->pictureInfo==null) $this->pictureInfo = getimagesize($this->pictureName) or die('Error getting picture info. Double check file path.'); return image_type_to_mime_type( $this->pictureInfo[2] ); } public function stampPicture(){ // get picture info such as width, height and extension // http://php.net/manual/en/function.getimagesize.php $this->pictureInfo = getimagesize($this->pictureName) or die('Error getting picture info. Double check file path.'); $this->stampInfo = getimagesize($this->stampName) or die('Error getting stamp info. Double check file path.'); // open images with class method openImage() $this->pictureFile = $this->openImage($this->pictureName, $this->pictureInfo[2]); $this->stampFile = $this->openImage($this->stampName, $this->stampInfo[2]); // position the stamp in the lower right corner $this->stampXpos = $this->pictureInfo[0] - $this->stampInfo[0] - 15; // width - width - margin $this->stampYpos = $this->pictureInfo[1] - $this->stampInfo[1] - 15; // height - height - margin // set a new name for the stamped picture and keep the original picture intact $this->newPictureName = $this->prefix.$this->pictureName; // alpha blending: http://php.net/manual/en/function.imagealphablending.php imagealphablending($this->pictureFile, true); // merge the two images: http://php.net/manual/en/function.imagecopymerge.php imagecopymerge($this->pictureFile, $this->stampFile, $this->stampXpos, $this->stampYpos, 0, 0, $this->stampInfo[0], $this->stampInfo[1], 100); if($this->savetofile){ // output the stamped image as GIF, JPG/JPEG or PNG. Add more types if needed. // default type is the same as the original file // GIF: http://php.net/manual/en/function.imagegif.php // JPG/JPEG: http://php.net/manual/en/function.imagejpeg.php // PNG: http://php.net/manual/en/function.imagepng.php switch ($this->pictureInfo[2]){ case 1: // GIF if($this->savetofile) imagegif($this->pictureFile, $this->newPictureName); else imagegif($this->pictureFile); break;// case 1 case 2:// JPG/JPEG if($this->savetofile) imagejpeg($this->pictureFile, $this->newPictureName); else imagejpeg($this->pictureFile); break;// case 2 case 3: // PNG if($this->savetofile) imagepng($this->pictureFile, $this->newPictureName); else imagepng($this->pictureFile); break;// case 3 default: die('Unsupported filetype: '.$fileName); } }elseif(!$this->savetofile && in_array($this->pictureInfo[2], array(1, 2, 3))){ //Return type will be image/jpeg if $this->savetofile is false imagejpeg($this->pictureFile); }else{ die('Unsupported filetype: '.$fileName); } return true; }// end of stampPicture function destruct(){ unset($fileHandle, $newPictureName, $pictureInfo, $pictureName, $prefix, $stampInfo, $stampName, $stampXpos, $stampYpos); }// end of destruct }// end of class ?> Der har jeg fikset klassen til deg Nå kan du kjøre f.eks denne koden: <?php $wm = new LiteStamp("bilde.jpg", "watermark.jpg", false); header("Content-Type: ".$wm->getImagetype()); $wm->stampPicture(); ?> Jeg håper i alle fall det TAkk takk! Var ikke meninga du skulle fikse hele, men er seff takknemlig! =) Skal prøve når jeg kommer hjem. Fylkeskommunen nekter deverre all tilgang til servere.. Lenke til kommentar
Gjest Slettet+142 Skrevet 29. oktober 2007 Del Skrevet 29. oktober 2007 Jeh, de har dessverre det Derfor har jeg ikke testet om skriptet funker. Men jeg hadde ikke så mye annet nyttig å gjøre på, så jeg bare fikset (med mindre feilmld. da) skriptet Lenke til kommentar
HoaXed Skrevet 29. oktober 2007 Forfatter Del Skrevet 29. oktober 2007 Jeh, de har dessverre det Derfor har jeg ikke testet om skriptet funker.Men jeg hadde ikke så mye annet nyttig å gjøre på, så jeg bare fikset (med mindre feilmld. da) skriptet Fungerte glimrende! Rask og grei kode Eneste som manglet var bare selve funksjonsinkluderin så alt var konge! Nå blir Fredrikstad Cups nye sider pene. Lenke til kommentar
Gjest Slettet+142 Skrevet 29. oktober 2007 Del Skrevet 29. oktober 2007 Det er bra Godt å vite at dette funket. - Jeg har jo ikke engang tenkt på skriptet siden skolen idag filinkluderingen tenkte jeg du klarte selv, så lot den være ute. Lenke til kommentar
Anbefalte innlegg
Opprett en konto eller logg inn for å kommentere
Du må være et medlem for å kunne skrive en kommentar
Opprett konto
Det er enkelt å melde seg inn for å starte en ny konto!
Start en kontoLogg inn
Har du allerede en konto? Logg inn her.
Logg inn nå