forum.coppermine-gallery.net
Support => Older/other versions => cpg1.1.X Support (standalone) => Topic started by: DJAxion on September 25, 2003, 10:22:41 pm
-
As promised: the codes.
First create a file called 'logo.php' with this content:
<?
// SCHIPT BY DJ AXION
// e-mail: DJ@the-expansion.com
// Enjoy this script!
// GET SOURCE PICTURE FROM FORM INPUT
include("imageinfo.php");
$myimage = New ImageInformation($picturename);
// These Version Jiggleing is pain in the ass
if (function_exists("imagegif")) {
$gi["GIF Read Support"] = 1;
}elseif (function_exists("imagejpeg")) {
$gi["JPG Support"] = 1;
}elseif (function_exists("imagepng")) {
$gi["PNG Support"] = 1;
}
// Try to dicide
if ($type = $myimage->format) {
switch ($type) {
case 'JPEG' :
if ($gi["JPG Support"]){
$b = imagecreatefromjpeg($picturename);
} else {
$image = $picturename;
}
break;
case 'GIF' :
if ($gi["GIF Read Support"]) {
$b = imagecreatefromgif($picturename);
} else {
$image = $picturename;
}
break;
case 'PNG' :
if ($gi["PNG Support"]){
$b = imagecreatefrompng($picturename);
} else {
$image = $picturename;
}
break;
}
}
$bx = $myimage->details["width"];// source width
$by = $myimage->details["height"]; // source height
if(!empty($b)) {
$lm = $b;
if ($bx > 200) { // this ensures no watermark is added to small images (e.g. thumbnails)
// ADD WATERMARK
$pos = "bottomright"; //where is the watermark displayed...
if ($pos == "topleft") {
$src_x = 0;
$src_y = 0;
} else if ($pos == "topright") {
$src_x = $bx - 193;
$src_y = 0;
} else if ($pos == "bottomleft") {
$src_x = 0;
$src_y = $by - 187;
} else if ($pos == "bottomright") {
$src_x = $bx - 90;
$src_y = $by - 90;
}
// THIS IS THE CODE FOR THE WATERMARK
ImageAlphaBlending($lm, true) or die ("Could not alpha blend"); // Enable when on GD 2+
$logoImage = ImageCreateFromPNG('logo.png'); // logo.png is a watermark it add's...
$logoW = ImageSX($logoImage);
$logoH = ImageSY($logoImage);
ImageCopy($lm,$logoImage,$src_x,$src_y,0,0,$logoW,$logoH);
}
}
if ($myimage->format && !empty($b)) {
Header("Content-type: image/$type");
switch ($type) {
case 'JPEG' :
Imagejpeg($lm,'',60); //80 means JPEG quality
break;
case 'GIF' :
ImageGif($lm);
break;
case 'PNG' :
ImagePnG($lm);
break;
}
imageDestroy($lm);
} else {
// No usable GD image Function ? Ok preventing brocken Images and give back the untouched Image
Header("Content-type: image/$type");
$fp = fopen($image,"r");
$fa = fread($fp,filesize ($image));
print($fa);
fclose($fp);
}
?>
Then a file 'imageinfo.php':
<?php
/*
ImageInformation PHP Class
This PHP class takes a local file as its input and will determine
if the file is a BMP, GIF, JPEG or PNG. It will also extract
other generic information about the image, including resolution,
height and width (without using the builtin GetImageSize() function)
as well as other image type specific information.
ImageInformation class is a part port of the perl module Image-Info.
I have not ported all of it as I really only required resolution,
jpeg_type and some other bits from gifs, jpegs and pngs. But I have
done some other bits as well. If anybody implements this better or
cleans it up send me a copy please.
Download here ImageInformation.tar.gz.
mike@nux.co.uk
http://mike.nux.co.uk/
---------------------------------------------------------------
usage:
include($includepath."get_imgsize.inc");
$myimage = New ImageInformation($file);
$width = $myimage->details["width"];
$height = $myimage->details["height"];
show full picture information
print_r($myimage->details);
show errors:
echo $myimage->errors
show file-Format:
echo $myimage->format
---------------------------------------------------------------
External Files (BMP.inc, GIF.inc, JPEG.inc, PNG.inc included into this
Class by Christian Rütgers <chr@1komma6.com> (www.1komma6.com)
Changed some attribut-strings from details[]
*/
Class ImageInformation {
var $errors;
var $source;
var $details;
var $format;
function ImageInformation($myfile){
$this->source = fopen ($myfile, "r");
$format = $this->GetFileFormat();
if($format != "unknown"){
$this->format = $format;
switch($this->format) {
case 'GIF':
$this->details = $this->ProcessFileGIF($this->source);
break;
case 'JPEG':
$this->details = $this->ProcessFileJPEG($this->source);
break;
case 'BMP':
$this->details = $this->ProcessFileBMP($this->source);
break;
case 'PNG':
$this->details = $this->ProcessFilePNG($this->source);
break;
}
}else{
$this->details = array();
$this->format = "unknown";
}
fclose ($this->source);
}
function GetFileFormat(){
$head = fread($this->source, 32);
if(preg_match("/^\xFF\xD8/",$head)){
return "JPEG";
}elseif(preg_match("/^GIF8[79]a/",$head)){
return "GIF";
}elseif(preg_match("/^BM/",$head)){
return "BMP";
}elseif(preg_match("/^\x89PNG\x0d\x0a\x1a\x0a/",$head)){
return "PNG";
}else{
return "unknown";
}
#return "ASCII" if /^[\011\012\015\040-\176]*$/ && $_ !~ m%(^<\?xml)|(^#define\s+)|(^/\* XPM \*/)|(static\s+char\s+\*\w+\[\]\s*=\s*{\s*"\d+)%;
#return "PPM" if /^P[1-6]/;;
#return "SVG" if /^<\?xml/;
#return "XBM" if /^#define\s+/;
#return "XPM" if /(^\/\* XPM \*\/)|(static\s+char\s+\*\w+\[\]\s*=\s*{\s*"\d+)/;
}
function ShowDetails(){
$keys = array_keys($this->details);
$out = '';
foreach ($keys as $key) {
$out .= $key.": ".$this->details[$key]."<BR>";
}
return $out;
}
function ProcessFileGIF ($source){
#Global $ImageInformation;
rewind($source);
$head = fread ($source, 13);
if(!eregi ("^GIF(8[79]a)", $head)){
die ("Bad GIF signature");
}
preg_match("/^GIF(8[79]a)/",$head,$matches);
$version = $matches[0];
$head = str_replace($matches[0],"",$head);
$version = str_replace("GIF","",$version);
$ImageInformation["GIF_Version"] = $version;
$vars = unpack("vsw/vsh/Cpacked/Cbg/Caspect",$head);
#showdata($vars);
$ImageInformation["width"] = $vars["sw"];
$ImageInformation["height"] = $vars["sh"];
$color_table_size = (1 << (($vars["packed"] & 7) + 1));
$ImageInformation["ColorTableSize"] = $color_table_size;
//not sure below stuff is return the correct values
if(($vars["packed"] & 8) > 0){
$sorted_colors = ($vars["packed"] & 8);
}else{
$sorted_colors = 0;
}
$ImageInformation["SortedColors"] = $sorted_colors;
if ($version == "89a"){
$ImageInformation["ColorResolution"] = ((($vars["packed"] & 112) >> 4) + 1);
$global_color_table = ($vars["packed"] & 128);
if($global_color_table){
$ImageInformation["GlobalColorTableFlag"] = 1;
$ImageInformation["BackgroundColor"] = $vars["bg"];
}else{
$ImageInformation["GlobalColorTableFlag"] = 0;
}
if($vars["aspect"]){
$aspect = ($vars["aspect"] + 15) / 64;
$ImageInformation["PixelAspectRatio"] = $aspect;
$ImageInformation["resolution"] = "1/".$aspect;
}else{
$ImageInformation["resolution"] = "1/1";
}
}
$ImageInformation["file_media_type"] = "image/gif";
$ImageInformation["file_ext"] = "gif";
return $ImageInformation;
}
function ProcessFileBMP($source){
$ImageInformation = array();
rewind($source);
$buf = fread($source, 54);
$header = unpack("Szero/Lone/Stwo/Sthree/Lfour/Lfive/Vwidth/Vheight/Ssamplesperpixel/Scolor_type/Lfile_ext/Leleven/Vresa/Vresb/Lcolortablesize/Lcolorsimportant", $buf);
extract(unpack("Szero/Lone/Stwo/Sthree/Lfour/Lfive/Vwidth/Vheight/Ssamplesperpixel/Scolor_type/Lfile_ext/Leleven/Vresa/Vresb/Lcolortablesize/Lcolorsimportant", $buf));
$total += strlen($buf);
$ImageInformation["file_media_type"] = "image/bmp";
if(($file_ext == 1) || ($file_ext == 2)){
$ImageInformation["file_ext"] = "rle";
}else{
$ImageInformation["file_ext"] = "bmp";
}
$ImageInformation["width"] = abs($width);
$ImageInformation["height"] = abs($height);
if($color_type & ($color_type < 24)){
$ImageInformation["color_type"] = "Indexed-RGB";
}else{
$ImageInformation["color_type"] = "RGB";
}
$ImageInformation["SamplesPerPixel"] = $samplesperpixel;
$ImageInformation["BitsPerSample"] = $color_type;
$ImageInformation["resolution"] = "$resa/$resb";
$ImageInformation["BMP_ColorsImportant"] = $colorsimportant;
$ImageInformation["ColorTableSize"] = $colortablesize;
if($height > 1) {
$ImageInformation["BMP_Origin"] = 1; //dunno if this is correct
}else{
$ImageInformation["BMP_Origin"] = 0; //dunno if this is correct
}
$compression = $file_ext;
$compressions = array('none','RLE8','RLE4','BITFIELDS','JPEG','PNG');
if(isset($compressions[$compression])){
$compression = $compressions[$compression];
}
$ImageInformation["Compression"] = $compression;
return $ImageInformation;
}
function ProcessFilePNG ($source){
$ImageInformation = array();
rewind($source);
$signature = fread($source, 8);
if($signature != "\x89PNG\x0d\x0a\x1a\x0a"){
die("Bad PNG signature");
}
$ImageInformation["file_media_type"] = "image/png";
$ImageInformation["file_ext"] = "png";
while(1){
extract(unpack("Nlen/a4type", fread($source, 8)));
/*
if($chunks){
$last = prev($chunks);
end($chunks);
//extract count digits from $last
preg_match("/\s(\d+)$/",$last,$matches);
if($matches[0]){
$last = str_replace($matches[0],"",$last);
$count = $matches[0];
}else{
$count = 1;
}
if($last == $type){
$count++;
$chunks[$count-1] = "$type $count";
}else{
array_push($chunks,$type);
}
}else{
$chunks = array();
array_push($chunks,$type);
}
*/
if ($type == "IEND"){
break;
}
$data = fread($source, $len + 4);
# $datavars = unpack("Nmycrc", substr($data, -4, 4));
if (($type == "IHDR") && ($len == 13)) {
extract(unpack("Nwidth/Nheight/Cdepth/Cctype/Ccompression/Cfilter/Cinterlace", $data));
$ImageInformation["width"] = $width;
$ImageInformation["height"] = $height;
$ImageInformation["SampleFormat"] = "U$depth";
$ctypes = array(0=>"Gray",2=>"RGB",3=>"Indexed-RGB",4=>"GrayA",6=>"RGBA");
if(isset($ctypes[$ctype])){
$ImageInformation["color_type"] = $ctypes[$ctype];
}else{
$ImageInformation["color_type"] = "PNG-$ctype";
}
if($compression == 0){
$compression = "Deflate";
}
$ImageInformation["Compression"] = $compression;
if($filter == 0){
$filter = "Adaptive";
}
$ImageInformation["PNG_Filter"] = $filter;
if($interlace == 1){
$interlace = "Adam7";
}
$ImageInformation["Interlace"] = $interlace;
}elseif($type == "PLTE"){
$paltable = array();
$no = 0;
while($no < strlen($data)){
extract(unpack("Cchar1/Cchar2/Cchar3", substr($data, 0, 3)));
array_push($paltable,sprintf("#%02x%02x%02x",$char1,$char2,$char3));
$no++;
}
$ImageInformation["ColorPalette"] = $paltable; //dunno if this is correct
}elseif(($type == "gAMA") && ($len == 4)){
extract(unpack("Ngamma", $data));
$ImageInformation["Gamma"] = $gamma/100000;
}elseif(($type == "pHYs") && ($len == 9)){
extract(unpack("Nres_x/Nres_y/Cunit",$data));
if ((0 && $unit) == 1) {
# convert to dpi
$unit = "dpi";
$res_x = $res_x * 0.0254;
$res_y = $res_y * 0.0254;
}
if($res_x == $res_y){
$res = $res_x;
}else{
$res = "$res_x/$res_y";
}
if ($unit) {
if ($unit == 1) {
$res .= " dpm";
}else{
$res .= " png-unit-$unit";
}
}
$ImageInformation["resolution"] = $res;
#}elseif($type == "tEXt"){
#my($key, $val) = split(/\0/, $data, 2);
## XXX should make sure $key is not in conflict with any
## other key we might generate
#$info->push_info(0, $key, $val);
}elseif(($type == "tIME") && ($len == 7)){
$mt = unpack("nyear/Cmonth/Cday/Chour/Cminute/Csecond", $data);
$ImageInformation["LastModificationTime"] = sprintf("%04d-%02d-%02d %02d:%02d:%02d",$mt["year"],$mt["month"],$mt["day"],$mt["hour"],$mt["minute"],$mt["second"]);
//}elseif($type == "sBIT"){
//$sb = unpack("C*", $data);
//$ImageInformation["SignificantBits"] = "";
}elseif($type == "IDAT"){
//ignore image data
}else{
$ImageInformation["Chunk-$type"] = $data; //unknown chunk type
}
}
if(!isset($ImageInformation["resolution"])){
$ImageInformation["resolution"] = "1/1";
}
//$ImageInformation["PNG_Chunks"] = $chunks;
return $ImageInformation;
}
function process_app0_jfxx($data){
$code = ord(substr($data, 0, 1));
if($code == 16){
$type = "JPEG thumbnail";
}elseif($code == 17){
$type = "Bitmap thumbnail";
}elseif($code == 19){
$type = "RGB thumbnail";
}else{
$type = "Unknown extention code $code";
}
$ImageInformation["JFXX_ImageType"] = $type;
// if ($code == 0x10) {
// eval {
// require IO::String;
// my $thumb_fh = IO::String->new($data);
// _process_file($info, $thumb_fh, 1);
// };
// $info->push_info(1, "error" => $@) if $@;
// }
}
function process_app14_adobe($data){
Global $ImageInformation;
extract(unpack("nversion/nflaga/nflagb/Ctransform",$data));
$ImageInformation["AdobeTransformVersion"] = $version;
$ImageInformation["AdobeTransformFlags"] = array($flags0,$flags1);
$ImageInformation["AdobeTransform"] = $transform;
}
function process_app0_jfif($data){
Global $ImageInformation;
if(strlen($data) < 9){
$ImageInformation["Debug"] = "Short JFIF chunk";
return;
}
extract(unpack("Cver_hi/Cver_lo/Cunit/nx_density/ny_density/Cx_thumb/Cy_thumb", substr($data, 0, 9)));
$ImageInformation["JFIF_Version"] = sprintf("%d.%02d", $ver_hi, $ver_lo);
if(($x_density != $y_density) | !$unit){
$res = $x_density."/".$y_density;
}else{
$res = $x_density;
}
if($unit){
$units = array("pixels","dpi","dpcm");
if(isset($units[$unit])){
$res .= " ".$units[$unit];
}else{
$res .= " jfif-unit-".$unit;
}
}
$ImageInformation["resolution"] = $res;
if($x_thumb | $y_thumb){
$ImageInformation["width"] = $x_thumb;
$ImageInformation["height"] = $y_thumb;
$ImageInformation["ByteCount"] = strlen($data);
}
}
function process_app($mark, $data){
Global $ImageInformation;
$app = $mark - 224;
$id = substr($data, 0, 5);
#$ImageInformation["Debug"] = $data;
$id = "$app-$id";
if($id == "0-JFIF\0"){
$this->process_app0_jfif(substr($data, 5));
}elseif($id == "0-JFXX\0"){
$this->process_app0_jfxx(substr($data, 5)); //not tested
}elseif($id == "1-Exif\0"){
$this->process_app1_exif(substr($data, 5)); //not converted yet
}elseif($id == "14-Adobe"){
$this->process_app14_adobe(substr($data, 5));
}else{
#$info->push_info(0, "App$id", $data);
#$ImageInformation["App$id"] = $data;
#printf " %s\n", Data::Dump::dump($data);
}
}
function process_chunk($mark, $data){
global $ImageInformation;
$JpegTypes = array('192' => "Baseline",
'193' => "Extended sequential",
'194' => "Progressive",
'195' => "Lossless",
'197' => "Differential sequential",
'198' => "Differential progressive",
'199' => "Differential lossless",
'201' => "Extended sequential, arithmetic coding",
'202' => "Progressive, arithmetic coding",
'203' => "Lossless, arithmetic coding",
'205' => "Differential sequential, arithmetic coding",
'206' => "Differential progressive, arithmetic coding",
'207' => "Differential lossless, arithmetic coding");
if ($mark == 254) {
$ImageInformation["Comment"] = $data;
}elseif(($mark >= 224) & ($mark <= 239)){
$this->process_app($mark, $data);
}elseif($JpegTypes[$mark]){
extract(unpack("Cprecision/nheight/nwidth/Cnum_comp", substr($data, 0, 6)));
$ImageInformation["JPEG_Type"] = $JpegTypes[$mark];
$ImageInformation["width"] = $width;
$ImageInformation["height"] = $height;
$ImageInformation["SamplesPerPixel"] = $num_comp;
#for (1..$num_comp) {
#$info->push_info($img_no, "BitsPerSample", $precision);
//$ImageInformation["BitsPerSample"] = $precision;
#}
## XXX need to consider JFIF/Adobe markers to determine this...
if ($num_comp == 1) {
$ImageInformation["color_type"] = "Gray";
}elseif($num_comp == 3){
$ImageInformation["color_type"] = "YCbCr"; # or RGB ?
}elseif($num_comp == 4){
$ImageInformation["color_type"] = "CMYK"; # or YCCK ?
}
#if (1) {
# while (length($data)) {
# my($comp_id, $hv, $qtable) = unpack("CCC", substr($data, 0, 3, ""));
# $comp_id = {1 => "Y",2 => "Cb",3 => "Cr",82 => "R",71 => "G",66 => "B",}->{$comp_id} || $comp_id;
# $info->push_info(0, "ColorComponents", [$comp_id, $hv, $qtable]);
# }
#}
}
}
function ProcessFileJPEG($source){
Global $ImageInformation;
$ImageInformation = array();
rewind($source);
$soi = fread($source, 2);
if(!$soi == "\xFF\xD8"){
die ("SOI missing");
}
$ImageInformation["file_media_type"] = "image/jpeg";
$ImageInformation["file_ext"] = "jpg";
while (1) {
extract(unpack("Cff/Cmark/nlen", fread($source, 4)));
if ($ff != 255){
break;
}
if(($mark == 218) | ($mark == 217)){
break;
}
if($len < 2){
break;
}
$this->process_chunk($mark, fread($source, ($len - 2)));
}
return $ImageInformation;
}
}
?>
Then goto: '/include/functions.inc.php' and find this line:
return $url_prefix[$pic_row['url_prefix']]. path2url($pic_row['filepath']. $pic_prefix[$mode]. $pic_row['filename']);
Replace with this:
return 'logo.php?picturename='.$url_prefix[$pic_row['url_prefix']]. path2url($pic_row['filepath']. $pic_prefix[$mode]. $pic_row['filename']);
That's it...
DJ Axion
-
Wow! It's to early for me to make any real comments (still have to install and try it out), but it sounds great. Thanks for sharing.
-
i ge this error!!!
Fatal error: Call to undefined function: process_app1_exif() in /var/www/fotos/imageinfo.php on line 435
How do i solve it? I'm using apache and php4 from debian Sid ... :|
-
Hi
Can't get it to work! if i upload an image it appears to load ok but only a broken image is displayed. The image files have uploaded ok but the logo.png file has not been applied.
Any ideas?
Thanks
Mal
-
Have you considered cacheing the images which are watermarked?
Storage space is cheaper than computing power ;)
and how about using ImageMagick convert when it is available...
-
php must be compiled with --enable-exif option.
-
Yes. it works fine!
Thanks for this great script!!!!!
-
I'm getting these errors:
Warning: fread(): supplied argument is not a valid stream resource in D:\htdocs\gallery\imageinfo.php on line 82
Warning: fclose(): supplied argument is not a valid stream resource in D:\htdocs\gallery\imageinfo.php on line 78
Warning: Cannot modify header information - headers already sent by (output started at D:\htdocs\gallery\logo.php:1) in D:\htdocs\gallery\logo.php on line 97
Warning: fread(): supplied argument is not a valid stream resource in D:\htdocs\gallery\logo.php on line 99
Warning: fclose(): supplied argument is not a valid stream resource in D:\htdocs\gallery\logo.php on line 101
anyone knows what's wrong?
-
I installed the files and the watermarking is working, however whenever I display an image that has an upper case character in the file name I get the dreaded X broken link image. Any reason why this script doesn't support upper case characters in file names?
-
Same as curtg, watermark works, but when maximize, i get a cross, and no image/with logo.png
-
Sure you're sick of hearing this, but:
Watermarking is working (and quite nicely too) on all images until I try and view at full size. Then I get the ol' dreaded red cross.
I'm not having trouble with uppercase chars. some with u/c filenames work, some don't, some with numbers in filename work, some don't, and some simple filenames like 'aromawave.jpg' that refuse. but one thing that does seem definite is that digital camera names such as DCS003.jpg never maximise.
Maybe it's a filename length issue? or a filesize issue?
I don't care for now anyway, cos I'm going to hack out the ability to fully maximise. (btw, could we have an 'disable popup maximising' toggle in the config next version? not just for watermark bug workarounds, i just hate js popups of any nature)
Holding breath & crossing toes for future version with full watermarking...
T
-
I too tried to alter the script as it is not the same I tried the best i could
But the problem is this
the code you said to alter
return $url_prefix[$pic_row['url_prefix']]. path2url($pic_row['filepath']. $pic_prefix[$mode]. $pic_row['filename']);
the code that is actually there
$url_prefix = array(0 => $CONFIG['fullpath'],
);
}
return path2url($pic_row['filepath'] . $pic_prefix[$mode] . $pic_row['filename']);
not sure whats up with that
-
I have change a little the code of Dj Axion, now you don´t need the class, but still need gd 2
Cambie el codigo de Dj Axion un poco, no se necesita la clase, pero si gd 2
logo.php
<?
// SCHIPT BY DJ AXION
// e-mail: DJ@the-expansion.com
// Enjoy this script!
//Change by Aemege almonare[at]ing[dot]uchile[dot]cl
// GET SOURCE PICTURE FROM FORM INPUT
// These Version Jiggleing is pain in the ass
$datos=exif_read_data($picturename);
$logo= "/paht/to/logo.png"
if (function_exists("imagegif")) {
$gi["GIF Read Support"] = 1;
}elseif (function_exists("imagejpeg")) {
$gi["JPG Support"] = 1;
}elseif (function_exists("imagepng")) {
$gi["PNG Support"] = 1;
}
// Try to dicide
if ($type = $datos[MimeType]) {
switch ($type) {
case 'image/jpeg' :
if ($gi["JPG Support"]){
$b = imagecreatefromjpeg($picturename);
} else {
$image = $picturename;
}
break;
case 'iamge/gif' :
if ($gi["GIF Read Support"]) {
$b = imagecreatefromgif($picturename);
} else {
$image = $picturename;
}
break;
case 'imag/png' :
if ($gi["PNG Support"]){
$b = imagecreatefrompng($picturename);
} else {
$image = $picturename;
}
break;
}
}
$bx = $datos[COMPUTED][Width];// source width
$by = $datos[COMPUTED][Height]; // source height
if(!empty($b)) {
$lm = $b;
if ($bx > 200) { // this ensures no watermark is added to small images (e.g. thumbnails)
// ADD WATERMARK
$pos = "bottomleft"; //where is the watermark displayed...
// THIS IS THE CODE FOR THE WATERMARK
ImageAlphaBlending($lm, true) or die ("Could not alpha blend"); // Enable when on GD 2+
$logoImage = ImageCreateFromPNG($logo); // logo.png is a watermark it add's...
$logoW = ImageSX($logoImage);
$logoH = ImageSY($logoImage);
if ($pos == "topleft") {
$src_x = 0;
$src_y = 0;
} else if ($pos == "topright") {
$src_x = $bx - $logoH;
$src_y = 0;
} else if ($pos == "bottomleft") {
$src_x = 0;
$src_y = $by - $logoH;
} else if ($pos == "bottomright") {
$src_x = $bx - $logoW;
$src_y = $by - $logoH;
}
ImageCopy($lm,$logoImage,$src_x,$src_y,0,0,$logoW,$logoH);
}
}
if ($datos[MimeType] && !empty($b)) {
Header("Content-type: $datos[MimeType]");
switch ($type) {
case 'image/jpeg' :
Imagejpeg($lm,'',60); //80 means JPEG quality
break;
case 'image/gif' :
ImageGif($lm);
break;
case 'image/png' :
ImagePnG($lm);
break;
}
imageDestroy($lm);
} else {
// No usable GD image Function ? Ok preventing brocken Images and give back the untouched Image
Header("Content-type: image/$type");
$fp = fopen($image,"r");
$fa = fread($fp,filesize ($image));
print($fa);
fclose($fp);
}
?>
Then goto: '/include/functions.inc.php' and find this line:
Code:
return $url_prefix[$pic_row['url_prefix']]. path2url($pic_row['filepath']. $pic_prefix[$mode]. $pic_row['filename']);
Replace with this:
Code:
return 'logo.php?picturename='.$url_prefix[$pic_row['url_prefix']]. path2url($pic_row['filepath']. $pic_prefix[$mode]. $pic_row['filename']);
Saludos desde Chile
-
Thanks for your work - which version of Coppermine did you test this with?
-
He cambiado una poco el script, se necesita GD && PHP >=4.3.0, lo he probado en Coppermine Photo Gallery v1.3.1 con Apache, PHP 4.3.2 y GD bundled (2.0.12 compatible)
Ahora la marca de agua puede ser un jpeg, gif o png, lo unico que hay que cambiar en el script es la tura relativa al archivo de la marca de agua.
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
I have change some the script, you need GD && PHP >=4.3.0, I have tested in Coppermine Photo Gallery v1.3.1 with Apache, PHP 4.3.2 and GD bundled (2.0.12 compatible)
Now you can use as watermark jpeg, gif or png files, you only need to alter the relative path to the watermark file.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Salu2 desde Chile
El script se debe llamar logo.php y tiene que estar en la carpeta principal del Coppermine, no en el include/
-------------------------------------------------------------------------------------------------------------------------------------------
The script must called logo.php and must be located in the first folder of Coppermine, not in include/
<?
// SCHIPT BY DJ AXION
// e-mail: DJ@the-expansion.com
// Enjoy this script!
// [b]Altered by Aemege almonare[at]ing[dot]uchile[dot]cl[/b]
// Need GD && PHP >= 4.3.0
$logo="../relative/paht/to/watermark.ext";
$datos[foto][tipo]=exif_imagetype($picturename);
$datos[logo][tipo]=exif_imagetype($logo);
$datos[foto][MimeType]=mimetype($datos[foto][tipo]);
if (function_exists("imagegif")) {
$gi["GIF Read Support"] = 1;
}elseif (function_exists("imagejpeg")) {
$gi["JPG Support"] = 1;
}elseif (function_exists("imagepng")) {
$gi["PNG Support"] = 1;
}
// Try to dicide
if ($datos[foto][tipo]) {
switch ($datos[foto][tipo]) {
case '2' :
if ($gi["JPG Support"]){
$b = imagecreatefromjpeg($picturename);
} else {
$image = $picturename;
}
break;
case '1' :
if ($gi["GIF Read Support"]) {
$b = imagecreatefromgif($picturename);
} else {
$image = $picturename;
}
break;
case '3' :
if ($gi["PNG Support"]){
$b = imagecreatefrompng($picturename);
} else {
$image = $picturename;
}
break;
}
}
$bx = ImageSX($b);
$by = ImageSY($b);
if(!empty($b)) {
$lm = $b;
if ($bx > 200) { // this ensures no watermark is added to small images (e.g. thumbnails)
// ADD WATERMARK
$pos = "bottomleft"; //where is the watermark displayed...
// Try to dicide the Logo Vemos que tipo de archivo es el logo
if ($datos[logo][tipo]) {
switch ($datos[logo][tipo]) {
case '1' :
$logoImage=imagecreatefromgif($logo);
break;
case '2' :
$logoImage=imagecreatefromjpeg($logo);
break;
case '3' :
$logoImage=imagecreatefrompng($logo);
break;
}
}
// THIS IS THE CODE FOR THE WATERMARK
ImageAlphaBlending($lm, true) or die ("Could not alpha blend"); // Enable when on GD 2+
$logoW = ImageSX($logoImage);
$logoH = ImageSY($logoImage);
if ($pos == "topleft") {
$src_x = 0;
$src_y = 0;
} else if ($pos == "topright") {
$src_x = $bx - $logoW;
$src_y = 0;
} else if ($pos == "bottomleft") {
$src_x = 0;
$src_y = $by - $logoH;
} else if ($pos == "bottomright") {
$src_x = $bx - $logoW;
$src_y = $by - $logoH;
}
ImageCopy($lm,$logoImage,$src_x,$src_y,0,0,$logoW,$logoH);
}
}
if ($datos[foto][MimeType] && !empty($b)) {
Header("Content-type: $datos[foto][Mimetype]");
switch ($datos[foto][tipo]) {
case 1:
ImageGif($lm);
break;
case 2:
Imagejpeg($lm,'',60); //80 means JPEG quality
break;
case 3:
ImagePnG($lm);
break;
}
imageDestroy($lm);
} else {
// No usable GD image Function ? Ok preventing brocken Images and give back the untouched Image
Header("Content-type: $datos[foto][MimeType]");
$fp = fopen($image,"r");
$fa = fread($fp,filesize ($image));
print($fa);
fclose($fp);
}
function mimetype($tipo){
switch($tipo){
case 1:
return "image/gif";
case 2:
return "image/jpeg";
case 3;
return "image/png";
default:
return "";
}
}
?>
Then goto: '/include/functions.inc.php' and find this line:
return $url_prefix[$pic_row['url_prefix']]. path2url($pic_row['filepath']. $pic_prefix[$mode]. $pic_row['filename']);
Replace with this:
return 'logo.php?picturename='.$url_prefix[$pic_row['url_prefix']]. path2url($pic_row['filepath']. $pic_prefix[$mode]. $pic_row['filename']);
-
this should be moved to another board then, users will never find you mod here...
GauGau
-
Pls I need this to work with CPG 1.3.2
-
There are watermark mods for 1.3.2.
Why are you posting this on the old 1.1 version support boards? Just search the mods/add ons/hacks board, and they are near the top.
-
Because this one is not really a prement watermark.
-
it seems the changes by aemege above allow this to work with 1.3.1, which means it should be ok with 1.3.2 as well.
Try it and let us know.
-
Ok i try the script by aemege and i doens't work i get the x for broken image link.
-
Could you post a link with an example?
-
http://www.maderacoyotes.com/photos/displayimage.php?album=11&pos=2
gd
=============================
GD Support enabled
GD Version bundled (2.0.28 compatible)
FreeType Support enabled
FreeType Linkage with freetype
GIF Read Support enabled
GIF Create Support enabled
JPG Support enabled
PNG Support enabled
WBMP Support enabled
XBM Support enabled
-
Warning: imagesx(): supplied argument is not a valid Image resource in /home/maderaco/public_html/photos/logo.php on line 50
That's the error message I am getting.
-
Ok Now i got some errors:
Warning: imagesx(): supplied argument is not a valid Image resource in /home/m/public_html/photos/logo.php on line 50
Warning: imagesy(): supplied argument is not a valid Image resource in /home/m/public_html/photos/logo.php on line 51
-
Ok this script still works on 1.3.2 version but i got two differnet servers one the script work on and the other it doesn't.
zpeek: This one it work on:
Configure Command './configure' '--with-apxs=/usr/local/apache/bin/apxs' '--with-xml' '--enable-bcmath' '--enable-calendar' '--enable-ftp' '--with-gd' '--with-jpeg-dir=/usr/local' '--with-png-dir=/usr' '--with-xpm-dir=/usr/X11R6' '--with-mcrypt' '--enable-magic-quotes' '--with-mysql=/usr' '--enable-discard-path' '--with-pear' '--enable-sockets' '--enable-track-vars' '--with-ttf' '--with-freetype-dir=/usr' '--enable-gd-native-ttf' '--enable-versioning' '--with-zlib'
maderacoyotes: This one it doesn't work:
Configure Command './configure' '--with-apxs=/usr/local/apache/bin/apxs' '--with-xml' '--enable-bcmath' '--enable-calendar' '--with-curl' '--with-dom' '--with-dom-xslt' '--with-dom-exslt' '--enable-exif' '--with-swf=/usr/local/flash' '--enable-ftp' '--with-gd' '--with-jpeg-dir=/usr/local' '--with-png-dir=/usr' '--with-xpm-dir=/usr/X11R6' '--with-gettext' '--with-imap' '--with-imap-ssl' '--with-kerberos' '--enable-mbstring' '--enable-mbstr-enc-trans' '--enable-mbregex' '--with-mcrypt' '--with-mhash' '--with-ming=../ming-0.2a' '--enable-magic-quotes' '--with-mysql=/usr' '--with-openssl' '--enable-discard-path' '--with-pear' '--enable-xslt' '--with-xslt-sablot' '--enable-sockets' '--enable-track-vars' '--with-ttf' '--with-freetype-dir=/usr' '--enable-gd-native-ttf' '--enable-versioning' '--enable-wddx' '--with-xmlrpc' '--with-zlib'
And i can't see what the problem is