我有一个常用于创建缩略图的功能,直到现在才出现问题。
我的src文件是:4ddice.com/img/large/000000/0400.png
我的目标文件是:4ddice.com/img/thumb/000000/0400.jpg
如果你看图片,你会看到src有一个白色背景,但dest有一个黑色背景。我无法弄清楚它为什么会这样做,但它正在发生在我尝试的每一个渲染中。 Render multiple stl files on windows machine有我用来创建渲染的代码。我想也许我的问题是因为我正在更改文件类型但是将输出更改为png格式无法修复(更不用说缩略图了。)
这是我用来制作缩略图的代码。
ini_set('memory_limit', '756M');
define('MAX_PROCESS_SIZE',400); //should be a little smaller then above.
//create thumbnail
function makeThumb($src, $dest, $maxWidth, $maxHeight) {
//get original image domentions
list($width, $height, $type, $attr) = getimagesize($src);
//get height if locking to max with
$desiredHeight = floor($height * ($maxWidth / $width));
//get width if locking to max height
$desiredWidth = floor($width * ($maxHeight / $height));
//chose correct values
$newHeight=$maxHeight;
$newWidth=$maxWidth;
if ($desiredHeight<$maxHeight) {
$newHeight=$desiredHeight;
}
if ($desiredWidth<$maxWidth) {
$newWidth=$desiredWidth;
}
//see if have enough ram
$neededRam=($newWidth*$newHeight+$width*$height)*5/1000000;
if ($neededRam>MAX_PROCESS_SIZE) {
return;
}
//read the source image
$sourceImage = imagecreatefrompng($src);
//create a new, "virtual" image
$virtualImage = imagecreatetruecolor($newWidth, $newHeight);
//copy source image at a resized size
imagecopyresampled($virtualImage, $sourceImage, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
/* create the physical thumbnail image to its destination */
imagejpeg($virtualImage, $dest,83);
//clear variables
imagedestroy($sourceImage);
imagedestroy($virtualImage);
//don't overload the server
sleep(1);
}