Skip to content

Instantly share code, notes, and snippets.

@mgng
Created May 31, 2010 08:20
Show Gist options
  • Save mgng/419651 to your computer and use it in GitHub Desktop.
Save mgng/419651 to your computer and use it in GitHub Desktop.
透過pngのリサイズ(imagick使用)
<?php
/**
* @param string $in
* @param string $out
* @param int $per
*/
function resizePng($in, $out, $per) {
$size = getimagesize($in);
if ($size === false || $size['mime'] !== 'image/png') {
return false;
}
$w = $size[0];
$h = $size[1];
$nw = floor($w*$per/100);
$nh = floor($h*$per/100);
$image = new Imagick();
$image->readImage($in);
$image->setImageFileName($out);
$image->resizeImage($nw, $nh, imagick::FILTER_SINC, 1);
$image->writeImage();
return true;
}
resizePng('test1.png', 'test1_imagick_resize.png', 50);
resizePng('test2.png', 'test2_imagick_resize.png', 50);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment