Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ildarkhasanshin/e47d65378814ec4caf964450a629e430 to your computer and use it in GitHub Desktop.
Save ildarkhasanshin/e47d65378814ec4caf964450a629e430 to your computer and use it in GitHub Desktop.
php-скрипт для оквадрачивания изображения с мутным задним фоном
<?php
$dir_ = '.';
$scanned_directory = array_diff(scandir($dir_), array('..', '.'));
if (count($scanned_directory) > 0) {
foreach ($scanned_directory as $f_) {
$imagick1 = new Imagick();
$imagick1->readImage($dir_.'/'.$f_);
$giw_ = $imagick1->getImageWidth();
$gih_ = $imagick1->getImageHeight();
$wh_max_ = max($giw_, $gih_);
$wh_min_ = min($giw_, $gih_);
$imagick1->resizeImage($wh_max_, $wh_max_, 1, 1);
$imagick1->setImageCompressionQuality(50);
$imagick1->radialBlurImage(30);
$quantumRange = $imagick1->getQuantumRange();
$quantumRange = $quantumRange['quantumRangeLong'];
$imagick1->levelImage(0, 2.0, $quantumRange+($quantumRange-($quantumRange/2)));
$tmp_dir = $dir_.'/_tmp';
if (is_dir($tmp_dir) === false) {
mkdir($tmp_dir, 0777);
}
$imagick1->writeImage($tmp_dir.'/'.$f_);
$imagick2 = new Imagick();
$imagick2->readImage($tmp_dir.'/'.$f_);
$imagick1 = new Imagick();
$imagick1->readImage($dir_.'/'.$f_);
if ($giw_ > $gih_) {
$cix_ = 0;
$ciy_ = ($wh_max_-$wh_min_)/2;
} else {
$cix_ = ($wh_max_-$wh_min_)/2;
$ciy_ = 0;
}
$imagick2->compositeImage($imagick1, Imagick::COMPOSITE_OVER, $cix_, $ciy_);
$res_dir = $dir_.'/_res';
if (is_dir($res_dir) === false) {
mkdir($res_dir, 0777);
}
$imagick2->writeImage($res_dir.'/'.$f_);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment