handler = $handler; } /** * Prototype definition for the scale filter. * @param int Height to scale to. * @param int Width to scale to. * @param int One of ezcImageFilters::SCALE_* constants. * * @param int $width Scaled to width * @param int $height Scaled to height * @param int $direction Scale to which direction */ public function scale( $width, $height, $direction ) { $dirMod = $this->getDirectionModifier( $direction ); $this->handler->addFilterOption( $this->handler->getActiveReference(), '-resize', $width.$dirMod.'!'.'x'.$height.$dirMod.'!' ); } /** * Returns the ImageMagick direction modifier for a direction constant. * ImageMagick supports the following modifiers to determine if an * image should be scaled up only, down only or in both directions: * * * SCALE_UP: > * SCALE_DOWN: < * * * This method returns the correct modifier for the internal direction * constants. * * @param int $direction One of ezcImageFiltersInterfaceGeometry::SCALE_* * @return string The correct modifier. */ protected function getDirectionModifier( $direction ) { $dirMod = ''; switch ( $direction ) { case self::SCALE_DOWN: $dirMod = '>'; break; case self::SCALE_UP: $dirMod = '<'; break; case self::SCALE_BOTH: default: $dirMod = '!'; break; } return $dirMod; } /** * Prototype definition for the scaleWidth filter. * @param int Width to scale to. * @param int One of ezcImageFilters::SCALE_* constants. * * @param int $width Scaled to width * @param int $direction Scale to which direction */ public function scaleWidth( $width, $direction ) { $dirMod = $this->getDirectionModifier( $direction ); $this->handler->addFilterOption( $this->handler->getActiveReference(), '-resize ', $width.$dirMod ); } /** * Prototype definition for the scaleHeight filter. * @param int Height to scale to. * @param int One of ezcImageFilters::SCALE_* constants. * * @param int $height Scaled to height * @param int $direction Scale to which direction */ public function scaleHeight( $height, $direction ) { $dirMod = $this->getDirectionModifier( $direction ); $this->handler->addFilterOption( $this->handler->getActiveReference(), '-resize ', 'x'.$height.$dirMod ); } /** * Prototype definition for the scalePercent filter. * @param int Height percent value. * @param int Width percent value. * * @param int $width Scale to width * @param int $height Scaled to height */ public function scalePercent( $width, $height ) { $this->handler->addFilterOption( $this->handler->getActiveReference(), '-resize', $width.'%x'.$height.'%' ); } /** * Prototype definition for the scaleExact filter. * @param int Height to scale to. * @param int Width to scale to. * * @param int $width Scale to width * @param int $height Scaled to height */ public function scaleExact( $width, $height ) { $this->handler->addFilterOption( $this->handler->getActiveReference(), '-resize', $width.'!x'.$height.'!' ); } /** * Prototype definition for the crop filter. * * @param int $xStart Start cropping, x coordinate. * @param int $yStart Start cropping, y coordinate. * @param int $xEnd End cropping, x coordinate. * @param int $yEnd End cropping, y coordinate. */ public function crop( $xStart, $yStart, $xEnd, $yEnd ) { $width = abs( $xEnd - $xStart ); $height = abs( $xEnd - $xStart ); $xStart = ( $xStart > 0 ) ? '+'.$xStart : $xStart; $yStart = ( $yStart > 0 ) ? '+'.$yStart : $yStart; $this->handler->addFilterOption( $this->handler->getActiveReference(), '-crop ', $width.'x'.$height.$xStart.'x'.$yStart ); } /** * Prototype for the colorspace filter. * @param int Colorspace, one of ezcImageFilters::COLORSPACE_* constants. * * @param $space The colorspace to convert to. */ public function colorspace( $space ) { switch ( $space ) { case self::COLORSPACE_GREY: $this->handler->addFilterOption( $this->handler->getActiveReference(), '-colorspace', 'GRAY' ); $this->handler->addFilterOption( $this->handler->getActiveReference(), '-colors', '255' ); break; case self::COLORSPACE_MONOCHROME: $this->handler->addFilterOption( $this->handler->getActiveReference(), '-monochrome', '' ); $this->handler->addFilterOption( $this->handler->getActiveReference(), '-colors', '2' ); break; case self::COLORSPACE_SEPIA: $this->handler->addFilterOption( $this->handler->getActiveReference(), '-sepia-tone', '80%' ); break; return; default: throw new ezcImageFiltersException( 'Unknown colorspace.', ezcImageFiltersException::INVALID_PARAMETER ); break; } } /** * Prototype definition for the noise filter. * @param int Noise value. * * @param int $value Intense of noise */ public function noise( $value ) { $value = ucfirst( strtolower( $value ) ); $possibleValues = array( 'Uniform', 'Gaussian', 'Multiplicative', 'Impulse', 'Laplacian', 'Poisson', ); if ( !in_array( $value, $possibleValues ) ) { throw new ezcImageFiltersException( 'Unknown noise value <'.$value.'>.', ezcImageFiltersException::INVALID_PARAMETER ); } $this->handler->addFilterOption( $this->handler->getActiveReference(), '+noise', $value ); } /** * Prototype definition for the swirl filter. * @param int Swirl value. * * @param int $value Intense of swirl */ public function swirl( $value ) { $this->handler->addFilterOption( $this->handler->getActiveReference(), '-swirl', $value ); } /** * Prototype for the border adding filter. * @param int Width of the border. * @param array(int) Color of the border (RGB, decimal). * * @param int $width Width of the border * @param array(int) $color Color */ public function border( $width, $color ) { $colorString = '#'; $i = 0; foreach ( $color as $id => $colorVal ) { if ( $i++ > 2 ) { break; } $colorString .= sprintf( '%02x', $colorVal ); } $this->handler->addFilterOption( $this->handler->getActiveReference(), '-bordercolor', $colorString ); $this->handler->addFilterOption( $this->handler->getActiveReference(), '-border', $width ); } } ?>