컬러와 흑백으로 분리해야하는 이미지 디렉토리가 있습니다. 이것은 이미지 magik getImageType을 사용하여 쉽게 감지 할 수있었습니다. 그러나 일부 이미지는 흑백으로 간주되지만 약간의 색조가 있습니다.imagemagick을 사용하여 이미지가 흑백 인 경우 그림은
로 트루 컬러 흑백으로 간주하지만, 돌아 오면 그 여전히 기술적으로 흑백
이미지를 일부 값을보고 결정하는 알려진 방법이 :
스크립트
<?php
$dir = getcwd();
$dirToImages = getcwd().'/imagesToScan/';
$files = scandir($dirToImages);
$badFiles = array('.DS_Store', '.', '..', 'index.php', 'bAndW', 'color');
@mkdir('colour');
@mkdir('bAndW');
echo "\n\n starting script, counting images: \n\n";
echo "image count: ".count($files)." \n\n ";
foreach($files as $file) {
/* if the file is shit, its not an image, skip it */
if (in_array($file, $badFiles)) {
continue;
}
/* directories or bad files don't have an extension, fool proof */
$exploded = explode('.', $file);
if (!isset($exploded[1])) {
continue;
}
echo $file;
/* okay do the work */
$imagick_type = new Imagick();
$file_to_grab = $dirToImages.'/'.$file;
$file_handle_for_viewing_image_file = fopen($file_to_grab, 'a+');
$imagick_type->readImageFile($file_handle_for_viewing_image_file);
$image_type = $imagick_type->getImageType();
switch($image_type)
{
case imagick::IMGTYPE_UNDEFINED:
$image_type_title = "Undefined";
break;
case imagick::IMGTYPE_BILEVEL:
$image_type_title = "Bilevel";
break;
case imagick::IMGTYPE_GRAYSCALE:
$image_type_title = "Grayscale";
break;
case imagick::IMGTYPE_GRAYSCALEMATTE:
$image_type_title = "Grayscale Matte";
break;
case imagick::IMGTYPE_PALETTE:
$image_type_title = "Palette";
break;
case imagick::IMGTYPE_PALETTEMATTE:
$image_type_title = "Palette Matte";
break;
case imagick::IMGTYPE_TRUECOLOR:
$image_type_title = "Truecolor";
break;
case imagick::IMGTYPE_TRUECOLORMATTE:
$image_type_title = "Truecolor Matte";
break;
case imagick::IMGTYPE_COLORSEPARATION:
$image_type_title = "Color Separation";
break;
case imagick::IMGTYPE_COLORSEPARATIONMATTE:
$image_type_title = "Color Separation Matte";
break;
case imagick::IMGTYPE_OPTIMIZE:
$image_type_title = "Optimize";
break;
}
if ($image_type == 2) {
// copy($dirToImages.'/'.$file, $dir.'/bAndW/'.$file);
} else {
// copy($dirToImages.'/'.$file, $dir.'/colour/'.$file);
}
echo $file."
\n Filename: ".$image_type.":
\n Type: ".$image_type_title ."
\n reddPrimary: ".print_r($imagick_type->getImageRedPrimary(),true)."
\n getImageBackgroundColor: ".print_r($imagick_type->getImageBackgroundColor(),true)."
\n ColourSpace: ".print_r($imagick_type->getColorspace(),true)."
\n\n ";
}
가
Heres는 스크립트의 출력은, 화상의 파일명은
starting script, counting images:
image count: 8
523340_10151281257702912_1277096031_n-fixed.jpg523340_10151281257702912_1277096031_n-fixed.jpg
Filename: 6:
Type: Truecolor
reddPrimary: Array
(
[x] => 0.63999998569489
[y] => 0.33000001311302
)
getImageBackgroundColor: ImagickPixel Object
(
)
ColourSpace: 0
black-and-white.jpgblack-and-white.jpg
Filename: 6:
Type: Truecolor
reddPrimary: Array
(
[x] => 0.63999998569489
[y] => 0.33000001311302
)
getImageBackgroundColor: ImagickPixel Object
(
)
ColourSpace: 0
colour-gif.gifcolour-gif.gif
Filename: 5:
Type: Palette Matte
reddPrimary: Array
(
[x] => 0.63999998569489
[y] => 0.33000001311302
)
getImageBackgroundColor: ImagickPixel Object
(
)
ColourSpace: 0
colour-image.pngcolour-image.png
Filename: 6:
Type: Truecolor
reddPrimary: Array
(
[x] => 0.63999998569489
[y] => 0.33000001311302
)
getImageBackgroundColor: ImagickPixel Object
(
)
ColourSpace: 0
yellow-should-be-black-and-white.jpgyellow-should-be-black-and-white.jpg
Filename: 6:
Type: Truecolor
reddPrimary: Array
(
[x] => 0.63999998569489
[y] => 0.33000001311302
)
getImageBackgroundColor: ImagickPixel Object
(
)
ColourSpace: 0
,536,913,632 멀리 수득 10
복제 된 회색조 버전의 이미지를 원본과 비교합니까? http://www.imagemagick.org/Usage/compare/#type_greyscale 어떻게 PHP에서 보일지 확실하지 않음 – mzmm56
http://stackoverflow.com/questions/23922654/detect-if-image-is-grayscale-or- color-using-imagick –