0
이미지를 최적화하는 명령 줄 도구에 사용되는 아래 PHP 함수가 있습니다. 아래 함수는 전달 된 모든 파일에서 ImageMagick을 실행하고 파일 확장명을 가져옵니다. .ImageMagick이 비 이미지를 전달할 때 오류가 발생합니다.
오늘 밤까지 실제 이미지 파일에서만 테스트했습니다. 나는 혼합 이미지 및 기타 파일이있는 폴더를 테스트했다. 그 결과이 같은 오류가
...
identify.exe: no decode delegate for this image format
`E:\Server\img\testfiles\archive.php' @ error/constitute.c/ReadImage/532.
지금 나는 그것이 비 이미지가 출력 파일 필터링 가지 어려운 알고 이 함수는 특별히 그 값을 결정하기위한 것일 때 .... 그러나이 상황을 처리 할 수있는 더 좋은 방법이 있습니다. 이미지가 아닌 파일이 내 프로그램을 통해이 함수에 전달되면 오류를 그 (것)들이 일어나기에서 피하십시오?
기능 ...
/**
* is_image
* @param mixed $file_path
* @static
* @access public
* @return void
*/
public static function is_image($file_path)
{
if (!file_exists($file_path)) {
throw new FileNotFoundException("File or path not found: " . $file_path);
}
$types = array("gif", "png", "gifgif", "jpg", "jpeg", "bmp");
//exec("/usr/bin/identify -quiet -format \"%m\" $file_path", $return, $error);
$imagemagick = self::$program_paths['imagemagick'] . '\identify';
exec($imagemagick . ' -quiet -format %m ' . $file_path, $return, $error);
$type = ($error === 0) ? mb_strtolower($return[0]) : "";
if ($error == 1) {
return false;
}
if (substr($type, 0, 6) === "gifgif") {
$type = "gifgif";
}
return in_array($type, $types);
}