カラーと白黒に分ける必要がある画像のディレクトリがあります。これは、image magik getImageType を使用して簡単に検出できました。ただし、一部の画像は白黒と見なされますが、黄色の色合いが含まれています。
いくつかの値を見て、まだ技術的に白黒を判断する既知の方法はありますか
白黒としてカウントされますが、本来の色として返される画像:
脚本
<?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 ";
}
スクリプトの出力は次のとおりです。画像のファイル名はそれを提供します
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