function createWaterMark($src_image = "") { if (!IsMagickWand($src_image)) { $src_image = NewMagickWand(); MagickReadImage($src_image, $this->src_image_name); } if (!$src_image) { return false; } $src_image_w = MagickGetImageWidth($src_image); $src_image_h = MagickGetImageHeight($src_image); if ($this->wm_image_name) { $wm_image_info = $this->getInfo($this->wm_image_name); if (!$wm_image_info) { return false; } $wm_image = NewMagickWand(); MagickReadImage($wm_image, $this->wm_image_name); $wm_image_w = MagickGetImageWidth($wm_image); $wm_image_h = MagickGetImageHeight($wm_image); $temp_wm_image = $this->getPos($src_image_w, $src_image_h, $this->wm_image_pos, $wm_image); $wm_image_x = $temp_wm_image["dest_x"]; $wm_image_y = $temp_wm_image["dest_y"]; $opacity0 = MagickGetQuantumRange(); $opacity100 = 0; $opacitypercent = $this->wm_image_transition; $opacity = $opacity0 - $opacity0 * $opacitypercent / 100; if ($opacity > $opacity0) { $opacity = $opacity0; } elseif ($opacity < 0) { $opacity = 0; } MagickSetImageIndex($wm_image, 0); MagickSetImageType($wm_image, MW_TrueColorMatteType); MagickEvaluateImage($wm_image, MW_SubtractEvaluateOperator, $opacity, MW_OpacityChannel); MagickCompositeImage($src_image, $wm_image, MW_OverCompositeOp, $wm_image_x, $wm_image_y); } if ($this->wm_text) { $this->wm_text = $this->wm_text; $temp_wm_text = $this->getPos($src_image_w, $src_image_h, $this->wm_image_pos); $wm_text_x = $temp_wm_text["dest_x"]; $wm_text_y = $temp_wm_text["dest_y"]; $drawing_wand = NewDrawingWand(); if ($this->wm_text_font != "") { DrawSetFont($drawing_wand, $this->wm_text_font); } DrawSetFontSize($drawing_wand, $this->wm_text_size); switch ($this->wm_image_pos) { case 0: DrawSetGravity($drawing_wand, MW_CenterGravity); break; case 1: DrawSetGravity($drawing_wand, MW_NorthWestGravity); break; case 2: DrawSetGravity($drawing_wand, MW_NorthEastGravity); break; case 3: DrawSetGravity($drawing_wand, MW_SouthEastGravity); break; case 4: DrawSetGravity($drawing_wand, MW_SouthWestGravity); break; case 5: DrawSetGravity($drawing_wand, MW_NorthGravity); break; case 6: DrawSetGravity($drawing_wand, MW_EastGravity); break; case 7: DrawSetGravity($drawing_wand, MW_SouthGravity); break; case 8: DrawSetGravity($drawing_wand, MW_WestGravity); break; default: DrawSetGravity($drawing_wand, MW_CenterGravity); break; } $pixel_wand = NewPixelWand(); if (preg_match("/([a-f0-9][a-f0-9])([a-f0-9][a-f0-9])([a-f0-9][a-f0-9])/i", $this->wm_text_color, $color)) { $red = hexdec($color[1]); $green = hexdec($color[2]); $blue = hexdec($color[3]); PixelSetColor($pixel_wand, "rgb({$red},{$green},{$blue})"); } else { PixelSetColor($pixel_wand, "rgb(255,255,255)"); } DrawSetFillColor($drawing_wand, $pixel_wand); MagickAnnotateImage($src_image, $drawing_wand, 0, 0, $this->wm_angle, $this->wm_text); } return $src_image; }
/** * liberty_magickwand_panorama_image - strictly speaking, this belongs in one of the image processing plugin files, but we'll leave it here for the moment * * @param array $pFileHash File hash - souce_file is required * @param array $pOptions * @access public * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure */ function liberty_magickwand_panorama_image(&$pFileHash, $pOptions = array()) { $magickWand = NewMagickWand(); $pFileHash['error'] = NULL; if (!empty($pFileHash['source_file']) && is_file($pFileHash['source_file'])) { if (!($pFileHash['error'] = liberty_magickwand_check_error(MagickReadImage($magickWand, $pFileHash['source_file']), $magickWand))) { // calculate border width $iwidth = round(MagickGetImageWidth($magickWand)); $iheight = round(MagickGetImageHeight($magickWand)); $aspect = $iwidth / $iheight; $metaHash = array('width' => $iwidth, 'height' => $iheight, 'aspect' => $aspect); // store original file information that we can adjust the viewer LibertyMime::storeMetaData($pFileHash['attachment_id'], 'PANO', $metaHash); // we need to pad the image if the aspect ratio is not 2:1 (give it a wee bit of leeway that we don't add annoying borders if not really needed) if ($aspect > 2.1 || $aspect < 1.9) { $bwidth = $bheight = 0; if ($aspect > 2) { $bheight = round(($iwidth / 2 - $iheight) / 2); } else { $bwidth = round(($iheight / 2 - $iwidth) / 2); } // if the ratio has nothing to do with a panorama image - i.e. gives us a negative number here, we won't generate a panorama image if ($bheight > 0) { $pixelWand = NewPixelWand(); PixelSetColor($pixelWand, !empty($pOptions['background']) ? $pOptions['background'] : 'black'); if (!($pFileHash['error'] = liberty_magickwand_check_error(MagickBorderImage($magickWand, $pixelWand, $bwidth, $bheight), $magickWand))) { if (!($pFileHash['error'] = liberty_magickwand_check_error(MagickWriteImage($magickWand, $pFileHash['source_file']), $magickWand))) { // yay! } } DestroyPixelWand($pixelWand); } } } } DestroyMagickWand($magickWand); return empty($pFileHash['error']); }
checkWandError(MagickAddNoiseImage($mgck_wnd, MW_LaplacianNoise), $mgck_wnd, __LINE__); checkWandError(MagickSetImageDelay($mgck_wnd, $noise_delay), $mgck_wnd, __LINE__); } $pre_morph_wnd =& checkWandError(MagickGetImage($mgck_wnd), $mgck_wnd, __LINE__); $red = mt_rand(0, 255); $green = mt_rand(0, 255); $blue = mt_rand(0, 255); checkWandError(PixelSetColor($pxl_wnd, "rgb({$red}, {$green}, {$blue})"), $pxl_wnd, __LINE__); DrawSetFillColor($drw_wnd, $pxl_wnd); DrawRoundRectangle($drw_wnd, $x1, $y1, $x2, $y2, $x_radius, $y_radius); drawNewImageSetDelay($pre_morph_wnd, $drw_wnd, $width, $height, $bg_color, $morph_delay, __LINE__); addMorphedImages($mgck_wnd, $pre_morph_wnd, $num_morph_frames, $morph_delay, __LINE__); DestroyMagickWand($pre_morph_wnd); MagickSetLastIterator($mgck_wnd); for ($i = $cnt_down_start; $i > 0 && $x2 - $x1 >= $x_int && $y2 - $y1 >= $y_int; $i--) { checkWandError(PixelSetColor($pxl_wnd, "rgb({$red}, {$green}, {$blue})"), $pxl_wnd, __LINE__); DrawSetFillColor($drw_wnd, $pxl_wnd); DrawRoundRectangle($drw_wnd, $x1, $y1, $x2, $y2, $x_radius, $y_radius); $red = mt_rand(0, 255); $green = mt_rand(0, 255); $blue = mt_rand(0, 255); $x1 += $x_int; $y1 += $y_int; $x2 -= $x_int; $y2 -= $y_int; drawNewImageSetDelay($mgck_wnd, $drw_wnd, $width, $height, $bg_color, $cnt_down_delay, __LINE__); addText($txt_wnd, $white, $font_size, $i); checkWandError(MagickDrawImage($mgck_wnd, $txt_wnd), $mgck_wnd, __LINE__); ClearDrawingWand($txt_wnd); } addText($drw_wnd, $white, $font_size, $i);