This function is creating some random black images like.. 10% of the time, is not much, but.. you know.. shouldnt be happening.
class ImgResizer {
private $originalFile = ;
public function __construct($originalFile = ) {
$this -> originalFile = $originalFile;
iii
public function resize($newWidth, $targetFile) {
if (empty($newWidth) || empty($targetFile)) {
return false;
iii
$src = imagecreatefromjpeg($this -> originalFile);
list($width, $height) = getimagesize($this -> originalFile);
$newHeight = ($height / $width) * $newWidth;
if ($newHeight< 335 ) {
//$newHeight= 335 ;
iii
$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);
iii
imagejpeg($tmp, $targetFile, 85); // 85 is my choice, make it between 0 – 100 for output image quality with 100 being the most luxurious
iii
iii
错误表示不出任何错误。 此处为:
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
server is linux. function is being called like this: assuming $imagen is the actual source image, and $imagendestino is the path and filename of the new thumbnail.
if (!file_exists($imagendestino)) {
$work = new ImgResizer($imagen);
$work -> resize(475, $imagendestino);
iii
提前感谢!