缩略图在php中生成图像问题

问题描述 投票:0回答:1

我写了下面的代码来生成php中的图像缩略图,它对于某些图像工作正常但是在高分辨率/高尺寸图像的情况下它显示

此页面无效

问题。这里imagecreatefromjpeg()不工作。这是什么解决方案请帮帮我..

function make_accused_thumb($src, $dest, $desired_width) {

/* read the source image */
//ini_set('gd.jpeg_ignore_warning', 1);
//echo $src;exit;
//echo $src;exit;
$source_image = @imagecreatefromjpeg($src);
echo $src;exit;
if (!$source_image)
{
  $source_image= @imagecreatefromstring(file_get_contents($src));
}

$width = @imagesx($source_image);
$height = @imagesy($source_image);

/* find the "desired height" of this thumbnail, relative to the desired width  */
$desired_height = @floor($height * ($desired_width / $width));

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

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

/* create the physical thumbnail image to its destination */
@header('Content-Type: image/jpeg');
@imagejpeg($virtual_image, $dest);

}
php laravel zend-framework
1个回答
0
投票

如果您在PHP应用程序中进行过任何类型的图像处理,那么您将开始意识到使用本机PHP命令(例如createimagefromjpg等)时的限制。它会占用您的Web服务器内存!如今,人们在手机中携带10百万像素摄像头,上传和调整照片大小可能会对资源造成压力,尤其是如果网站上的多个用户同时进行此操作。

为了解决这个难题,有一个名为imagick的PHP库(一个包装类),它允许您访问一个名为ImageMagick的终端程序。 ImageMagick在机器上本机运行,可用于Unix,Linux,Mac和Windows,因此运行它应该不是问题。这里唯一需要考虑的是您的托管服务提供商PHP是否具有想象力。如果没有,根据您的托管包,您可以SSH到您的服务器并安装它。

一旦我切换到使用IMagick PHP类,错误就停止了,网站也大大增加了。

以下是在Linux和Windows上安装的方法:

Howto: Install Imagick (for php) on Ubuntu 11.10

How to install ImageMagick to use with PHP on Windows 7 (3)

这是IMagick类的文档:http://be2.php.net/manual/en/class.imagick.php

© www.soinside.com 2019 - 2024. All rights reserved.