Skip to content

Instantly share code, notes, and snippets.

@sebbdk
Created September 30, 2012 18:33
Show Gist options
  • Select an option

  • Save sebbdk/3808095 to your computer and use it in GitHub Desktop.

Select an option

Save sebbdk/3808095 to your computer and use it in GitHub Desktop.
Configure::write('Assets.ImageSize.big_gift_distort', array(
'name' => 'price',
'callback' => function($Image) {
$maskPath = 'theme/jdag/img/mask/big_package_mask.png';
$mask = new Imagick($maskPath);
$Image->applyFilter('resize', array('width' => 0, 'height' => 270));
if($Image->getImageWidth() > 256) {
$Image->applyFilter('resize', array('width' => 256, 'height' => 0));
}
$Image->applyFilter('canvas', array('width' => 256, 'height' => 270));
// Set the image format to png
$Image->setImageFormat('png');
// Control points for the distortion
//each line is fromX,fromY , toX,toY
$controlPoints = array(
0,0, 0,0, #top left
$Image->getImageWidth(),0, $Image->getImageWidth(),0, #top right
$Image->getImageWidth(),$Image->getImageHeight(), $Image->getImageWidth()-10,$Image->getImageHeight(), #bottom right
0,$Image->getImageHeight(), 10,$Image->getImageHeight(), #bottom left
);
$Image->distortImage(Imagick::DISTORTION_PERSPECTIVE, $controlPoints, false);
$mask->setImageFormat('png');
$mask->compositeImage( $Image->getObject(), imagick::COMPOSITE_ATOP, 0, -15 );
$Image->setObject($mask);
}
));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment