<option value="tr" <?php echo osc_watermark_place() == 'tr' ? 'selected="true"' : ''; ?> ><?php _e('Top Right'); ?> </option> <option value="bl" <?php echo osc_watermark_place() == 'bl' ? 'selected="true"' : ''; ?> ><?php _e('Bottom Left'); ?> </option> <option value="br" <?php echo osc_watermark_place() == 'br' ? 'selected="true"' : ''; ?> ><?php _e('Bottom Right'); ?> </option> </select> </p> </div> </fieldset> <input id="button_save" type="submit" value="<?php _e('Update'); ?> " /> </form>
/** * Calculate offset acording to watermark alignment * * @param resource $image * @param array $opt * @return array */ private function calculateOffset($image, $text) { //, array $opt) { $offset = array('x' => 0, 'y' => 0); // get image size and calculate bounding box $isize = $this->getImageSize($image); $bbox = $this->calculateBBox($text); switch (osc_watermark_place()) { case 'tl': $offset['x'] = 1; $offset['y'] = $bbox['height'] + 1; break; case 'tr': $offset['x'] = $isize['x'] - $bbox['top_right']['x'] - 1; $offset['y'] = $bbox['height'] + 1; break; case 'bl': $offset['x'] = 1; $offset['y'] = $isize['y'] - 1; break; case 'br': $offset['x'] = $isize['x'] - $bbox['top_right']['x'] - 1; $offset['y'] = $isize['y'] - 1; break; default: $offset['x'] = $isize['x'] / 2 - $bbox['top_right']['x'] / 2; $offset['y'] = $isize['y'] / 2 - $bbox['top_right']['y'] / 2; break; } return $offset; }
public function doWatermarkImage() { $this->_watermarked = true; $path_watermark = osc_uploads_path() . 'watermark.png'; if (osc_use_imagick()) { $wm = new Imagick($path_watermark); $wgeo = $wm->getImageGeometry(); switch (osc_watermark_place()) { case 'tl': $dest_x = 0; $dest_y = 0; break; case 'tr': $dest_x = $this->_width - $wgeo['width']; $dest_y = 0; break; case 'bl': $dest_x = 0; $dest_y = $this->_height - $wgeo['height']; break; case 'br': $dest_x = $this->_width - $wgeo['width']; $dest_y = $this->_height - $wgeo['height']; break; default: $dest_x = ($this->_width - $wgeo['width']) / 2; $dest_y = ($this->_height - $wgeo['height']) / 2; break; } $this->im->compositeImage($wm, imagick::COMPOSITE_OVER, $dest_x, $dest_y); $wm->destroy(); } else { $watermark = imagecreatefrompng($path_watermark); $watermark_width = imagesx($watermark); $watermark_height = imagesy($watermark); switch (osc_watermark_place()) { case 'tl': $dest_x = 0; $dest_y = 0; break; case 'tr': $dest_x = $this->_width - $watermark_width; $dest_y = 0; break; case 'bl': $dest_x = 0; $dest_y = $this->_height - $watermark_height; break; case 'br': $dest_x = $this->_width - $watermark_width; $dest_y = $this->_height - $watermark_height; break; default: $dest_x = ($this->_width - $watermark_width) / 2; $dest_y = ($this->_height - $watermark_height) / 2; break; } $this->_imagecopymerge_alpha($this->im, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100); imagedestroy($watermark); } return $this; }