标签: gd

Heroku - 如何在heroku php应用程序上启用gd?

Heroku说:

以下内置扩展已经构建为"共享",可以通过composer.json(括号中给出的内部标识符名称)启用:

但它没有给出一个例子,我尝试使用以下composer.json: { "require": { "gd": "*" } }

但是,当我git push heroku master,我得到:

我的composer.json: { "require": { "gd": "*" } }

但是,当我git push heroku master,我得到:

-----> Installing dependencies...
       Composer version 1.0.0-alpha9-19-g10401d5 2014-12-09 11:32:02
       Loading composer repositories with package information
       Installing dependencies
       Your requirements could not be resolved to an installable set of packages.

         Problem 1
           - The requested package gd could not be found in any version, there may be a typo     in the package …
Run Code Online (Sandbox Code Playgroud)

php gd heroku

21
推荐指数
1
解决办法
9871
查看次数

PHP GD:如何将imagedata作为二进制字符串?

我正在使用一种解决方案将图像文件组合到一个zip并将其流式传输到浏览器/ Flex应用程序.(Paul Duncan的ZipStream,http://pablotron.org/software/zipstream-php/ ).

只需加载图像文件并压缩它们就可以了.这是压缩文件的核心:

// Reading the file and converting to string data
$stringdata = file_get_contents($imagefile);

// Compressing the string data
$zdata = gzdeflate($stringdata );
Run Code Online (Sandbox Code Playgroud)

我的问题是我想在压缩之前使用GD处理图像.因此,我需要一个解决方案,将图像数据(imagecreatefrompng)转换为字符串数据格式:

// Reading the file as GD image data
$imagedata = imagecreatefrompng($imagefile);
// Do some GD processing: Adding watermarks etc. No problem here...

// HOW TO DO THIS??? 
// convert the $imagedata to $stringdata - PROBLEM!

// Compressing the string data
$zdata = gzdeflate($stringdata );
Run Code Online (Sandbox Code Playgroud)

有线索吗?

php zip gd

20
推荐指数
3
解决办法
2万
查看次数

在将具有透明背景的PNG图像调整大小/转换为JPEG时,如何用白色替换黑色背景.

我正在使用一个允许用户上传图像的脚本.该脚本调整大小并将图像转换为JPEG.

我遇到的问题是当上传具有透明度的PNG时,生成的JPEG图像是黑色的,其中有透明度.

如何编辑以下脚本以将黑色替换为白色?它已经为GIF做了这个,但对PNG没做.

 // RESIZE IMAGE AND PUT IN USER DIRECTORY
  switch($this->file_ext)
{
    case "gif":
      $file = imagecreatetruecolor($width, $height);
      $new = imagecreatefromgif($this->file_tempname);
      $kek=imagecolorallocate($file, 255, 255, 255);
      imagefill($file,0,0,$kek);
      imagecopyresampled($file, $new, 0, 0, 0, 0, $width, $height, $this->file_width, $this->file_height);
      imagejpeg($file, $photo_dest, 100);
      ImageDestroy($new);
      ImageDestroy($file);
      break;

    case "bmp":
      $file = imagecreatetruecolor($width, $height);
      $new = $this->imagecreatefrombmp($this->file_tempname);
      for($i=0; $i<256; $i++) { imagecolorallocate($file, $i, $i, $i); }
      imagecopyresampled($file, $new, 0, 0, 0, 0, $width, $height, $this->file_width, $this->file_height); 
      imagejpeg($file, $photo_dest, 100);
      ImageDestroy($new);
      ImageDestroy($file);
      break;

    case "jpeg":
    case …
Run Code Online (Sandbox Code Playgroud)

php gd resize image

20
推荐指数
1
解决办法
2万
查看次数

PHP:如何从.ttf文件中读取字体的"标题"?

我真的需要能够从.ttf真实类型字体文件中提取元数据.

我正在构建一个我们所有设计师使用的所有字体的中央数据库(它们通过电子邮件交换字体以接管设计元素等).我想得到所有的字体,有些像00001.ttf那样愚蠢的名字,所以文件名没有帮助,但我知道字体有元数据,我需要一些方法在PHP中提取它.

然后我可以创建一个循环来查看我指定的目录,获取这些数据(以及我可以同时获得的任何其他数据,并将其添加到数据库中.

我真的需要帮助阅读这个元数据部分.

php fonts gd truetype

19
推荐指数
1
解决办法
1万
查看次数

使用GD和libjpeg支持编译PHP

我编译自己的PHP,部分是为了更多地了解PHP如何组合在一起,部分是因为我总是发现我需要默认情况下不可用的模块,这样我就可以控制它.

我的问题是我无法在PHP中获得JPEG支持.使用CentOS 5.6.以下是编译PHP 5.3.8时的配置选项:

 './configure'  '--enable-fpm' '--enable-mbstring' '--with-mysql' '--with-mysqli' '--with-gd' '--with-curl' '--with-mcrypt' '--with-zlib' '--with-pear' '--with-gmp' '--with-xsl' '--enable-zip' '--disable-fileinfo' '--with-jpeg-dir=/usr/lib/'
Run Code Online (Sandbox Code Playgroud)

./configure输出表示:

checking for GD support... yes
checking for the location of libjpeg... no
checking for the location of libpng... no
checking for the location of libXpm... no
Run Code Online (Sandbox Code Playgroud)

然后我们可以看到GD已安装,但JPEG支持不存在:

# php -r 'print_r(gd_info());'
Array
(
    [GD Version] => bundled (2.0.34 compatible)
    [FreeType Support] =>
    [T1Lib Support] =>
    [GIF Read Support] => 1
    [GIF Create Support] => 1
    [JPEG …
Run Code Online (Sandbox Code Playgroud)

php gd compilation centos libjpeg

19
推荐指数
2
解决办法
5万
查看次数

imageantialias在安装GD的情况下调用未定义的函数错误

我需要一个PHP脚本的帮助.它是一个已在网站中实施的CMS.尝试添加新产品IMAGE或尝试编辑当前图像时,我收到以下错误:

致命错误:在第233行的/home/mounts/home/m/mclh/web/admin/library/functions.php中调用未定义的函数imageantialias()

这是我对该领域的代码:

   if ($tmpDest['extension'] == "gif" || $tmpDest['extension'] == "jpg")
    {
       $destFile  = substr_replace($destFile, 'jpg', -3);
       $dest      = imagecreatetruecolor($w, $h);
       imageantialias($dest, TRUE);
    } elseif ($tmpDest['extension'] == "png") {
       $dest = imagecreatetruecolor($w, $h);
       imageantialias($dest, TRUE);
    } else {
      return false;
    }
Run Code Online (Sandbox Code Playgroud)

第233行是第5行.

php gd function

18
推荐指数
2
解决办法
2万
查看次数

从Url创建图像任何文件类型

我知道imagecreatefromgif(),imagecreatefromjpeg()imagecreatefrompng()但有一种方式来创建图像资源(最好PNG)从一个URL 任何类型的有效的形象?或者你必须确定文件类型,然后使用适当的功能?

当我说网址时,我的意思是http://sample.com/image.png,不是数据网址

php gd image

18
推荐指数
4
解决办法
5万
查看次数

是否阻止人们通过注射上传GIF?

我有一个PHP网站,人们可以在那里填写帮助票.它允许他们上传票证的屏幕截图.我允许上传gif,psd,bmp,jpg,png,tif.收到上载后,PHP脚本将忽略文件扩展名.它仅使用MIME信息标识文件类型,对于这些文件类型,它始终存储在文件的前12个字节中.

有人上传了几个GIF,当用浏览器查看时,浏览器说它无效,我的病毒扫描程序提醒我这是注射(或类似的东西).请参阅下面的包含这些GIF的zip文件.

我认为只检查标题信息是不够的.我听说图像可以完全有效,但也包含漏洞利用代码.

所以我有两个基本问题:

  1. 有谁知道他们是如何将坏东西注入GIF(同时仍然保持有效的GIF MIME类型)?如果我知道这一点,也许我可以在上传时检查它.
  2. 如何阻止某人上传此类文件?
    • 我在共享主机上,所以我无法安装服务器端病毒扫描程序.
    • 将信息提交到在线病毒扫描网站可能太慢了.
    • 有没有办法检查自己使用检查这些东西的PHP类?
    • 如果它无效,会使用GD失败调整图像大小吗?或者漏洞仍然会漏掉并进入已调整大小的图像?如果它失败了,那将是理想的,因为那时我可以使用调整大小作为一种技术来查看它们是否有效.

更新:大家,谢谢你的答复到目前为止.我试图在服务器上查找上传的GIF.如果我找到它们,我会更新这篇文章.

更新2:我为任何感兴趣的人找到了GIF.我把它们放在一个用密码"123"加密的zip文件中.它位于这里(小心这个主机网站上有多个"下载"按钮 - 其中一些是广告)http://www.filedropper.com/badgifs.名为5060.gif的版本被我的防病毒软件标记为特洛伊木马(TR/Graftor.Q.2).我应该注意这些文件是在我实现前12个字节的MIME检查之前上传的.所以现在,我对这些特殊的安全.但我仍然想知道如何检测隐藏在正确MIME类型后面的漏洞.


重要说明: 我只关心下载这些文件以查看它们的PC的风险. 这些文件对我的服务器没有风险.它们不会被执行.它们使用扩展名为".enc"的干净名称(十六进制散列输出)进行存储,然后使用fwrite过滤器将它们以加密状态保存到磁盘:

// Generate random key to encrypt this file.
$AsciiKey = '';
for($i = 0; $i < 20; $i++)
    $AsciiKey .= chr(mt_rand(1, 255));

// The proper key size for the encryption mode we're using is 256-bits (32-bytes).
// That's what "mcrypt_get_key_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC)" says.
// So we'll hash our key using SHA-256 and pass TRUE to the 2nd …
Run Code Online (Sandbox Code Playgroud)

php security gd image-processing code-injection

18
推荐指数
1
解决办法
4514
查看次数

将PNG放在PHP中的JPG上

我想在PHP中执行以下操作:

我有两个图像,一个jpg和一个png.我想将jpg的大小调整为与png相同的大小,然后将png置于顶部.PNG具有透明度,所以我想保留它,以便jpg显示在下面.

如果有人能提供帮助那就太棒了!

谢谢

php gd image image-processing

17
推荐指数
2
解决办法
5万
查看次数

当文本以数字开头时,imagettfbbox计算错误的矩形

问题是,当imagettfbbox用于计算文本尺寸时,当输入文本以数字开头时,会返回太小的矩形.这是我的代码:

$fontSize = 150;
$font = "font/courier_new.ttf";
$text = $_GET["text"];

//Determine font dimensions
$bbox = imagettfbbox($fontSize, 0, $font, $text);   
$bbox["width"]=  abs($bbox[4]-$bbox[0]);
$bbox["height"]= abs($bbox[5]-$bbox[1]);

$im = imagecreatetruecolor($bbox["width"], $bbox["height"]);

echo "<b>Image size:</b>\n";
print_r($bbox);

// This part makes transparent background
imagesavealpha($im, true);
$bg = imagecolorallocatealpha($im, 254, 254, 254,127); 
$text_color= imagecolorallocate($im, 0, 0, 0);
imagealphablending($im, false);
imagefilledrectangle($im, 0, 0, imagesx($im), imagesy($im), $bg );
imagealphablending($im, true); 


header("X-Img-Size: ".$bbox["width"]."x".$bbox["height"]."");

imagettftext($im, $fontSize, 0, 0, $bbox["height"], $text_color, $font, $text);

// This is output    
header("Content-Type: text/html");  
ob_start(); …
Run Code Online (Sandbox Code Playgroud)

php gd imagettftext

17
推荐指数
1
解决办法
2522
查看次数