Skip to content

Commit

Permalink
Don't use the deprecated clone method when possible.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrubinsk committed Jan 20, 2017
1 parent 5b0161c commit 3a61129
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 11 deletions.
Expand Up @@ -50,7 +50,7 @@ public function apply()
// which makes it pretty much impossible to have Imagick shadows look
// identical to Im shadows...
try {
$shadow = $this->_image->imagick->clone();
$shadow = $this->_image->cloneImagickObject();
$shadow->setImageBackgroundColor(new ImagickPixel('black'));
$shadow->shadowImage(
80,
Expand Down
6 changes: 3 additions & 3 deletions framework/Image/lib/Horde/Image/Effect/Imagick/PhotoStack.php
Expand Up @@ -110,7 +110,7 @@ public function apply()
);
} else {
$imgk->destroy();
$imgk = $topimg->clone();
$imgk = $this->_image->cloneImagickObject($topimg);
}
if ($this->_params['type'] == 'rounded') {
$imgk = $this->_roundBorder($imgk);
Expand All @@ -123,7 +123,7 @@ public function apply()
}
// Only shadow the bottom image for 'plain' stacks
if (!$haveBottom) {
$shad = $imgk->clone();
$shad = $this->_image->cloneImagickObject($imgk);
$shad->setImageBackgroundColor(
new ImagickPixel('black')
);
Expand Down Expand Up @@ -170,7 +170,7 @@ public function apply()
}
}
$result = $imgk->polaroidImage(new ImagickDraw(), $angle);

// Get the geometry of the image and remember the largest.
$geo = $imgk->getImageGeometry();
$length = max(
Expand Down
10 changes: 5 additions & 5 deletions framework/Image/lib/Horde/Image/Effect/Imagick/SmartCrop.php
Expand Up @@ -40,20 +40,20 @@ class Horde_Image_Effect_Imagick_SmartCrop extends Horde_Image_Effect
public function apply()
{
$this->_params = new Horde_Support_Array($this->_params);

// Existing geometry
$geometry = $this->_image->getDimensions();
$w0 = $geometry['width'];
$h0 = $geometry['height'];

$w = $this->_params->width;
$h = $this->_params->height;

// @TODO: Parameterize these
$r = 1; // radius of edge filter
$nk = 9; // scale count: number of crop sizes to try
$gamma = 0.2; // edge normalization parameter -- see documentation

// Target AR
$ar = $this->_params->width / $this->_params->height;

Expand All @@ -69,7 +69,7 @@ public function apply()

try {
// Compute COE
$img = $this->_image->imagick->clone();
$img = $this->_image->cloneImagickObject();
$img->edgeImage($r);
$img->modulateImage(100,0,100);
$img->blackThresholdImage("#0f0f0f");
Expand All @@ -94,7 +94,7 @@ public function apply()
$xcenter /= $sum;
$ycenter /= $sum;
$this->_logger->debug('COE: ' . $xcenter . 'x' . $ycenter);

// crop source img to target AR
if ($w0 / $h0 > $ar) {
// source AR wider than target
Expand Down
32 changes: 30 additions & 2 deletions framework/Image/lib/Horde/Image/Imagick.php
Expand Up @@ -709,14 +709,15 @@ public function __get($property)
* @param string $color The border color.
* @param integer $width The image width including the border.
* @param integer $height The image height including the border.
*
* @todo Make non-static for H6.
*/
public static function frameImage(&$image, $color, $width, $height)
{
// Need to jump through these hoops in order to preserve any
// transparency.
// @TODO Imagick::clone is deprecated as of 3.1.0. For H6 use the clone
// keyword instead.
try {
// @todo Use clone or $this->_cloneImagickObject().
$border = $image->clone();
$border->borderImage(new ImagickPixel($color), $width, $height);
$border->compositeImage($image, Imagick::COMPOSITE_COPY, $width, $height);
Expand Down Expand Up @@ -821,4 +822,31 @@ public function getImagePageCount()
{
return $this->_imagick->getNumberImages();
}


/**
* Wrapper around cloning the imagick resource object.
*
* @param Imagick $imagick A imagick resource object to clone. If empty
* will clone the imagick object associated with
* this Horde_Imagice_Imagick object.
*
* @todo Remove in H6 when we can increase version dependency of Imagick.
*
* @return Imagick
* @since 2.4.0
*/
public function cloneImagickObject($imagick = null)
{
if (version_compare(phpversion('imagick'), '3.1.0') >= 0) {
return empty($imagick)
? clone $this->_imagick
: clone $imagick;
}

return empty($imagick)
? $this->_imagick->clone()
: $imagick->clone();
}

}

0 comments on commit 3a61129

Please sign in to comment.