English 中文(简体)
如何检查一个PNG的光谱/甲色谱类型?
原标题:How to check a PNG for grayscale/alpha color type?
  • 时间:2010-01-13 15:40:55
  •  标签:
  • php
  • png
  • gd

PHP和GD在使用imagecreate frompng(时,似乎难以从PNGs中产生带有甲型的灰质。 这些结果被明显扭曲。

我想知道,是否有任何人知道如何测试肤色类型,以便通知使用者不兼容的情况?

例:

Original Image: http://dl.dropbox.com/u/246391/Robin.png
Resulting Image: http://dl.dropbox.com/u/246391/Robin_result.png

法典:

<?php

$resource = imagecreatefrompng( ./Robin.png );
header( Content-type: image/png );
imagepng($resource);
imagedestroy($resource);

Cheers,

Aron

最佳回答

PNG图像的颜色类型在档案中被逐字抵消25(从0)。 因此,如果你能够掌握全国过渡政府档案中的实际内容,那么简单地看看看25分(我不做购买力平价),那么我不知道如何做到:

  • 0 - greyscale
  • 2 - RGB
  • 3 - RGB with palette
  • 4 - greyscale + alpha
  • 6 - RGB + alpha

以前的星号(第24号)给出每个频道的比照数。 See the PNG spec

略微扭曲的是,PNG的档案可能具有“1-bit alpha”(如GIFs)的“tRNS chunk(如果是2或3的颜色)。

问题回答

i landed here today searching for a way to tell (via php) if a specific .png image is an alpha-png one -
David Jones answer points to the right direction, really easy to implement in php:

file_get_contents to load just that 25 byte (there it is, indeed!), and
ord() to get its ASCII value, to test it (against 6 in my case)

if(ord(file_get_contents($alpha_png_candidate, NULL, NULL, 25, 1)) == 6) {
  is_alpha_png_so_do_something();
  }

actually i needed that for assuring backward compatibility with ie6 within cms-user-generated-pages, to replace all alpha-png < img > tags with inline-block < spans > - the alpha-png file will then be served as variable for the ms-proprietary css property filter

.alpha_png_span{
  filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(
    src= $alpha_png_candidate , sizingMethod= crop )
  }

......所有工作都是如此。

paolo

see this answer :

Another usefull note for those using ImageCreateFromPng: PHP and GD do not recognize grayscale/alpha images.

www.un.org/Depts/DGACM/index_spanish.htm 因此,如果你在0%到100%之间以透明的方式使用光线图像,那么就拯救了RGB的形象。

至少在PHP版本4.4.2-1和5.1.2-1中,情况与GIP 2.2.8相同。

url : http://php.net/manual/en/function.imagecreatefrompng.php





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签