Skip to content

Instantly share code, notes, and snippets.

@cergey-obr
Created July 11, 2014 05:35
Show Gist options
  • Save cergey-obr/036d80fff4f1acebecb7 to your computer and use it in GitHub Desktop.
Save cergey-obr/036d80fff4f1acebecb7 to your computer and use it in GitHub Desktop.
Скрипт для получения обесцвеченной версии изображения
public function grayscale($img_path) {
$umiImg = new umiFile('.'.$img_path);
$gray_name = '/images/gray/'.str_replace('.'.$umiImg->getExt(), '', $umiImg->getFileName()).'_gray.jpg';
if (!file_exists('.'.$gray_name)) {
switch ($umiImg->getExt()) {
case 'jpg': $img = imagecreatefromjpeg($umiImg->getFilePath()); break;
case 'gif': $img = imagecreatefromgif($umiImg->getFilePath()); break;
case 'png': $img = imagecreatefrompng($umiImg->getFilePath()); break;
}
imagefilter($img, IMG_FILTER_GRAYSCALE);
imagejpeg($img, '.'.$gray_name, 100);
}
return $gray_name;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment