이 함수는 10 %의 시간과 같은 임의의 검은 색 이미지를 생성합니다. 은 그리 많지는 않지만 ... 일어날 일이 없습니다.PHP + GD 무작위 검정색 작은 이미지 생성
class ImgResizer {
private $originalFile = '';
public function __construct($originalFile = '') {
$this -> originalFile = $originalFile;
}
public function resize($newWidth, $targetFile) {
if (empty($newWidth) || empty($targetFile)) {
return false;
}
$src = imagecreatefromjpeg($this -> originalFile);
list($width, $height) = getimagesize($this -> originalFile);
$newHeight = ($height/$width) * $newWidth;
if ($newHeight<'335') {
//$newHeight='335';
}
$tmp = imagecreatetruecolor($newWidth, $newHeight);
#$tmp = imagecreate($newWidth, $newHeight);
imagecopyresampled($tmp, $src, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
if (file_exists($targetFile)) {
unlink($targetFile);
}
imagejpeg($tmp, $targetFile, 85); // 85 is my choice, make it between 0 – 100 for output image quality with 100 being the most luxurious
}
}
오류가의 error_log에 제공하지 않습니다. 여기에 gd_info()가 있습니다 :
Array(
[GD Version] => bundled (2.0.34 compatible)
[FreeType Support] =>
[T1Lib Support] =>
[GIF Read Support] => 1
[GIF Create Support] => 1
[JPG Support] => 1
[PNG Support] => 1
[WBMP Support] => 1
[XPM Support] => 1
[XBM Support] => 1
[JIS-mapped Japanese Font Support] =>)1
서버가 리눅스입니다. 함수는 다음과 같이 호출됩니다. $ imagen이 실제 소스 이미지이고 $ imagendestino가 새 축소판의 경로 및 파일 이름이라고 가정합니다.
if (!file_exists($imagendestino)) {
$work = new ImgResizer($imagen);
$work -> resize(475, $imagendestino);
}
미리 감사드립니다.
오류 로깅을 사용하도록 설정 했습니까? –
결정적으로 실패합니까? 나는. 출력은 항상 동일한 입력 파일에 대해 동일합니까? –