Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Watermarks in extension #12

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions classes/handlers/magick.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,57 @@ public function contrast( $value, $region = null )
);
}
}

/**
* (non-PHPdoc)
* @see ezcImageImagemagickHandler::watermarkAbsolute()
*/
public function watermarkAbsolute( $image, $posX, $posY, $width = false, $height = false )
{
if ( !is_string( $image ) || !file_exists( $image ) || !is_readable( $image ) )
{
throw new ezcBaseValueException( 'image', $image, 'string, path to an image file' );
}
if ( !is_int( $posX ) )
{
throw new ezcBaseValueException( 'posX', $posX, 'int' );
}
if ( !is_int( $posY ) )
{
throw new ezcBaseValueException( 'posY', $posY, 'int' );
}
if ( !is_int( $width ) && !is_bool( $width ) )
{
throw new ezcBaseValueException( 'width', $width, 'int/bool' );
}
if ( !is_int( $height ) && !is_bool( $height ) )
{
throw new ezcBaseValueException( 'height', $height, 'int/bool' );
}

$data = getimagesize( $this->getActiveResource() );

// Negative offsets
$posX = ( $posX >= 0 ) ? $posX : $data[0] + $posX;
$posY = ( $posY >= 0 ) ? $posY : $data[1] + $posY;

/*
* overridden to suppress third parameter
* @see https://issues.apache.org/jira/browse/ZETACOMP-55
*/
$this->addFilterOption(
$this->getActiveReference(),
'-composite'
);

$this->addFilterOption(
$this->getActiveReference(),
'-geometry',
( $width !== false ? $width : "" ) . ( $height !== false ? "x$height" : "" ) . "+$posX+$posY"
);

$this->addCompositeImage( $this->getActiveReference(), $image );
}
}

?>
29 changes: 26 additions & 3 deletions classes/image_tool_watermark.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ class eZIEImageToolWatermark extends eZIEImageAction
*/
public static function filter( $region, $image )
{
// the watermark images are in ezie/design/standard/images/watermarks
// @todo use ini file for image paths instead
$img_path = realpath( dirname( __FILE__ ) . "/../design/standard/images/watermarks" ) . "/" . $image;
$img_path = self::findWatermark( $image );

// retrieve image dimensions
$analyzer = new ezcImageAnalyzer( $img_path );
Expand All @@ -42,5 +40,30 @@ public static function filter( $region, $image )
)
);
}

/**
* Looks for $imageFileName in each extension watermark repository
* defined in image.ini and returns its complete path
*
* @param string $imageFileName Watermark file name
* @return string Watermark file path
* @throws ezcBaseFileNotFoundException
*/
public static function findWatermark( $imageFileName )
{
$ini = eZINI::instance( 'image.ini' );
$extensionRepositories = $ini->variable( 'eZIE', 'WatermarkExtensions' );
foreach( $extensionRepositories as $extension )
{
$path = 'extension/' . $extension . '/design/standard/images/watermarks/' . $imageFileName;
if( file_exists( $path ) )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to use eZURLOperator::eZImage() to get the path of the file, thus allowing overriding images in custom designs? There would be no need for WatermarkExtensions setting at all, just put the images in watermarks directory in any of designs in any of extensions?

{
return $path;
}
}

eZDebug::writeWarning( 'Could not find watermark ' . $imageFileName, __METHOD__ );
throw new ezcBaseFileNotFoundException( $imageFileName, 'image' );
}
}
?>
23 changes: 17 additions & 6 deletions modules/ezie/tool_watermark.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,23 @@

if ( $prepare_action->hasRegion() && $http->hasPostVariable( 'watermark_image' ) )
{
$imageconverter = new eZIEezcImageConverter(
eZIEImageToolWatermark::filter(
$prepare_action->getRegion(),
$http->variable( 'watermark_image' )
)
);
try{
$imageconverter = new eZIEezcImageConverter(
eZIEImageToolWatermark::filter(
$prepare_action->getRegion(),
$http->variable( 'watermark_image' )
)
);
}
catch( ezcBaseFileNotFoundException $e )
{
header( 'HTTP/1.0 500 Internal Server Error' );
if( eZDebug::isDebugEnabled() )
{
echo $e->getMessage();
}
eZExecution::cleanExit();
}
}
else
{
Expand Down
5 changes: 5 additions & 0 deletions settings/image.ini.append.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
# The settings must not be overriden in the extension.
#
[eZIE]
# Defines which extension contains watermarks
# Watermarks must be stored in design/standard/images/watermarks/ subdirectory
WatermarkExtensions[]
WatermarkExtensions[]=ezie

watermarks[]=elephpant.png
watermarks[]=ez-logo.png

Expand Down