我尝试用imagecopyresampled
更改调整大小的图像。问题是我有非常大的图像,它是25000像素x 25000像素。我试着在本地主机上启动,我的电脑安装了8gb RAM。PHP我得到错误:
Fatal error: Out of memory (allocated 1844969472) (tried to allocate 86400 bytes)
我尝试在php.ini文件memory_limit=6144M
和php文件ini_set('memory_limit', '-1');
中增加内存大小,但这对没有帮助
me代码:
public function copyResample($pasteStartX, $pasteStartY, $startCopyX, $startCopyY, $dstWidth, $dstHeight, $srcWidth, $srcHeight, $outputPathToFileWOExt) {
$dstImage = imagecreatetruecolor($dstWidth, $dstHeight);
switch ($this->getMimeType()) {
case 'image/jpg':
case 'image/jpeg':
$srcImage = imagecreatefromjpeg($this->getPathToFile());
break;
case 'image/png':
$srcImage = imagecreatefrompng($this->getPathToFile());
break;
case 'image/gif':
$srcImage = imagecreatefromgif($this->getPathToFile());
break;
default:
throw new Exception("File is not an image, please use another file type.", 1);
}
imagecopyresampled($dstImage, $srcImage, $pasteStartX, $pasteStartY, $startCopyX, $startCopyY, $dstWidth, $dstHeight, $srcWidth, $srcHeight);
switch ($this->getMimeType()) {
case 'image/jpg':
case 'image/jpeg':
if (imagetypes() && IMG_JPG) {
imagejpeg($dstImage, $outputPathToFileWOExt . "." . $this->getExt());
}
break;
case 'image/png':
if (imagetypes() && IMG_PNG) {
imagepng($dstImage, $outputPathToFileWOExt . "." . $this->getExt());
}
break;
case 'image/gif':
if (imagetypes() && IMG_GIF) {
imagegif($dstImage, $outputPathToFileWOExt . "." . $this->getExt());
}
break;
}
}
简单的事实是内存仍然不足。一个25000px 25000px像素的图像将需要大量的内存——如果你正在进行图像复制重采样,则需要双倍的内存。