我有功能,通过这个功能,我试图在我的服务器中创建一些图像
foreach($value[0] as $imagekey => $imageval) {
$imgname = $gancxadeba . '_' . $imagekey;
$saveaddr = dirname(dirname($_SERVER['PHP_SELF'])).'/www/classifieds_images/';
$as = '.JPG';
$originalname = $imgname . $as;
if(!file_exists($saveaddr.$originalname)) {
if (preg_match('/\.(jpg)$/', $imageval)) {
$getfile = imagecreatefromjpeg($imageval);
} elseif (preg_match('/\.(JPG)$/', $imageval)) {
$getfile = imagecreatefromjpeg($imageval);
} elseif (preg_match('/\.(png)$/', $imageval)) {
$getfile = imagecreatefrompng($imageval);
} else {
$getfile = imagecreatefromgif($imageval);
}
list($width, $height) = getimagesize($imageval);
$newWidth = 90;
$newHeight = 120;
$original = imagecreatetruecolor($width, $height);
imagecopyresampled($original, $getfile, 0, 0, 0, 0, $width, $height, $width, $height);
imagejpeg($original, "../www/classifieds_images/$originalname");
echo 'განცხადება: ' . $gancxadeba . ' ორიგინალი სურათი: ' . $imgname . ' created!' . PHP_EOL;
$thumbname = $imgname . '_THUMB' . $as;
if (!file_exists($saveaddr . $thumbname)) {
$thumb = imagecreatetruecolor($newWidth, $newHeight);
imagecopyresampled($thumb, $getfile, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
imagejpeg($thumb, "../www/classifieds_images/$thumbname");
echo 'განცხადება: ' . $gancxadeba . ' თამბი სურათი: ' . $imgname . ' created!' . PHP_EOL;
}
}
$image[$imagekey] = $imgname;
}
如您所知,m getting image link and then chacking if file exists and I
如果文件不存在,我将创建文件。但我的服务器变慢了。它使用 2GB RAM。我可以做些什么来加速我的服务器?
我首先尝试了 file_put_content(),然后创建了 thumb,但它的效果不如 gd 库。所以请帮我比现在更快地完成这个功能。