1

我目前正在使用 php gd 实现来调整不断耗尽内存的图像的大小 - 相当快。我想问题出在 php 函数上,比如 imagecreatefromstring 等。

是否有一个简单的实现来调整不使用此功能的图像大小,所以我不必增加我的 php.ini 内存限制?

4

2 回答 2

5

这是给你的PHP函数

 function make_thumb($src, $dest, $desired_width,$desired_h) {

  /* read the source image */
  $source_image = imagecreatefromjpeg($src);
  $width = imagesx($source_image);
  $height = imagesy($source_image);

  $desired_height = $desired_h;

  /* create a new, "virtual" image */
  $virtual_image = imagecreatetruecolor($desired_width, $desired_height);

  /* copy source image at a resized size */
  imagecopyresampled($virtual_image, $source_image, 0, 0, 0, 0, $desired_width, $desired_height, $width, $height);

  /* create the physical thumbnail image to its destination */
  imagejpeg($virtual_image, $dest);
}

来源:davidwalsh.name/create-image-thumbnail-php

于 2013-02-26T12:34:19.150 回答
1

GD 不会使用那么多内存,因此您的代码中还有其他问题。

如果您调整多个图像的大小并且不调用imagedestroy新创建的图像,则会在内存泄漏中运行。

于 2013-02-26T12:13:29.480 回答