function watermark(WOOF_Image $watermark, $attr = array()) { // setup default offsets, based on specified global $wf; $ic = $wf->get_image_class(); $r = wp_parse_args( $attr, array( "at" => "se", "inset" => 10, "alpha" => true, "q" => 90 )); $w = ""; $h = ""; if (isset($r["w"])) { $r["width"] = $r["w"]; } if (isset($r["h"])) { $r["height"] = $r["h"]; } if (isset($r["height"])) { $h = $r["height"]; } if (isset($r["width"])) { $w = $r["width"]; } if (isset($r["size"])) { $w = $r["size"]; } if (isset($h)) { if (preg_match("/(\d+)%/", $h, $m)) { $h = round(($m[1] / 100) * $this->height()); } } if (isset($w)) { if (preg_match("/(\d+)%/", $w, $m)) { $w = round(($m[1] / 100) * $this->width()); } } $os = ""; if (isset($r["offset"])) { $os = $r["offset"]; } $r["suffix"] = ".mark.".md5($watermark->filepath()).".".$r["at"].$r["inset"].$os.$w.$h; $ci = $this->cacheinfo($r); if (file_exists($ci["path"]) && !isset($r["nocache"])) { return new $ic( $ci["path"], $ci["url"], $this->attr() ); } else { // work out the offsets if (isset($r["offset"])) { $offset = self::parse_coord($r["offset"]); } else { $offset = self::get_offset($r["inset"], $r["at"]); } $image = WOOF_Image::load($this->filepath()); if (isset($w) && isset($h)) { $watermark = $watermark->resize("w=$w&h=$h&q=".$r["q"]); } else if (isset($w)) { $watermark = $watermark->resize("w=$w&q=".$r["q"]); } else if (isset($h)) { $watermark = $watermark->resize("h=$h&q=".$r["q"]); } $wimage = WOOF_Image::load($watermark->filepath()); $sw = $watermark->width(); $sh = $watermark->height(); $dw = $this->width(); $dh = $this->height(); // work out the position $coord = self::get_at_coord( $dw, $dh, $sw, $sh, $r["at"] ); // get final coord $fc = array( $coord[0] + $offset[0], $coord[1] + $offset[1] ); // Set the margins for the stamp and get the height/width of the stamp image $marge_right = 10; $marge_bottom = 10; // Merge the stamp onto our photo with an opacity (transparency) of 50% self::imagecopymerge_alpha($image, $wimage, $fc[0], $fc[1], 0, 0, $sw, $sh, 100); if ( self::save_image( $ci["path"], $image, $this->infer_content_type($r), $attr ) ) { return new $ic( $ci["path"], $ci["url"], $this->attr() ); } } }