【问题标题】:Thumbnails generating issue for images in phpphp中图像的缩略图生成问题
【发布时间】:2019-02-14 18:15:51
【问题描述】:

我编写了以下代码来为 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);

}

【问题讨论】:

  • 在您的服务器日志中,您可能会发现导致 500 错误的错误消息。
  • 删除exit; ?还有,Laravel,Zend-Framework?
  • 它适用于其他图像,只要大尺寸图像(4mb,6mb)不起作用..服务器仅处于登录模式
  • 控制不退出也显示此页面在更多尺寸图像的情况下无法正常工作

标签: php laravel zend-framework


【解决方案1】:

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

为了解决这个难题,有一个名为 imagick 的 PHP 库(一个包装类),它允许您访问一个名为 ImageMagick 的终端程序。 ImageMagick 在机器上本地运行,可用于 Unix、Linux、Mac 和 Windows,因此运行它应该没有问题。这里唯一要考虑的是您的托管服务提供商 PHP 是否有 imagick 可用。如果没有,根据您的托管包,您可能能够通过 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-07
    • 1970-01-01
    • 2014-10-24
    • 2016-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多