Что такое код imagecreatefromxpm

Содержание

imagecreatefromwbmp

Create a new image from file or URL

Description

imagecreatefromwbmp returns an image identifier representing the image obtained from the given filename.

A URL can be used as a filename with this function if the fopen wrappers have been enabled. See fopen for more details on how to specify the filename. See the Supported Protocols and Wrappers for links to information about what abilities the various wrappers have, notes on their usage, and information on any predefined variables they may provide.

Parameters

Path to the WBMP image.

Return Values

Returns an image resource identifier on success, FALSE on errors.

Examples

Example #1 Example to handle an error during loading of a WBMP

function LoadWBMP ( $imgname )
<
/* Attempt to open */
$im = @ imagecreatefromwbmp ( $imgname );

/* See if it failed */
if(! $im )
<
/* Create a blank image */
$im = imagecreatetruecolor ( 150 , 30 );
$bgc = imagecolorallocate ( $im , 255 , 255 , 255 );
$tc = imagecolorallocate ( $im , 0 , 0 , 0 );

imagefilledrectangle ( $im , 0 , 0 , 150 , 30 , $bgc );

/* Output an error message */
imagestring ( $im , 1 , 5 , 5 , ‘Error loading ‘ . $imgname , $tc );
>

header ( ‘Content-Type: image/vnd.wap.wbmp’ );

$img = LoadWBMP ( ‘bogus.image’ );

imagewbmp ( $img );
imagedestroy ( $img );
?>

Notes

Note: WBMP support is only available if PHP was compiled against GD-1.8 or later.

Windows versions of PHP prior to PHP 4.3.0 do not support access of remote files via this function, even if allow_url_fopen is enabled.

imagecreatefromxpm

(PHP 4 >= 4.0.1, PHP 5, PHP 7)

imagecreatefromxpm � ������� ����� ����������� �� ����� ��� URL

��������

imagecreatefromxpm() ���������� ������������� �����������, ��������������� ����������� ���������� �� ����� � �������� ������.

��� ���� ������� �� ������ ������������ URL � �������� ����� �����, ���� ���� �������� ����� fopen wrappers. �������� ����� ��������� ���������� �� ����������� ����� ����� � �������� ������� fopen() . �������� ����� ������ �������������� ������� URL, �� �����������, ��������� �� ������������� � ������ ���������������� �������� � ������� �������������� ��������� � �������.

������ ����������

���� � ����������� XPM.

������������ ��������

���������� ������ ����������� � ������ ������, ��� FALSE � ������ ������.

������ ���������

������ ��������
5.3.19 imagecreatefromxpm() �������� �� Windows.

�������

������ #1 �������� �����������, ��������� imagecreatefromxpm()

��� ����� ��� imagecreatefromxpm

(PHP 4 >= 4.0.1, PHP 5)

imagecreatefromwbmp — Create a new image from file or URL

Description resource imagecreatefromwbmp ( string filename )

imagecreatefromwbmp() returns an image identifier representing the image obtained from the given filename.

imagecreatefromwbmp() returns an empty string on failure. It also outputs an error message, which unfortunately displays as a broken link in a browser. To ease debugging the following example will produce an error WBMP :

Пример 1. Example to handle an error during creation (courtesy vic at zymsys dot com)

Замечание: WBMP support is only available if PHP was compiled against GD-1.8 or later.

Подсказка: Для этой функции вы можете использовать URL в качестве имени файла, если была включена опция «fopen wrappers». Смотрите более подробную информацию об определении имени файла в описании функции fopen() , а также список поддерживаемых протоколов URL в Прил. L .

Версии PHP для Windows до PHP 4.3.0 не поддерживают возможность использования удаленных файлов этой функцией даже в том случае, если опция allow_url_fopen включена.

Imagecreatefromxpm

Php �������


Php �������


imagecreatefromxpm

(PHP 4 >= 4.0.1, PHP 5)

imagecreatefromxpm — Create a new image from file or URL

Description

resource imagecreatefromxpm ( string filename )

imagecreatefromxpm() returns an image identifier representing the image obtained from the given filename.

���������: ��� ������� �������� ������ � ��� ������, ���� PHP ��� ������������� �� ���������� ����������� GD.

���������: ��� ���� ������� �� ������ ������������ URL � �������� ����� �����, ���� ���� �������� ����� » fopen wrappers». �������� ����� ��������� ���������� �� ����������� ����� ����� � �������� ������� fopen(), � ����� ������ �������������� ���������� URL � ����. M.

Внимание

������ PHP ��� Windows �� PHP 4.3.0 �� ������������ ����������� ������������� ��������� ������ ���� �������� ���� � ��� ������, ���� ����� allow_url_fopen ��������.

User Contributed Notes

There are no user contributed notes for this page

��� ����� ��� imagecreatefromxpm

imagecreatefromwbmp — ������ ����� ����������� �� ����� ��� URL.

��������

resource imagecreatefromwbmp (string filename)

imagecreatefromwbmp() ���������� ������������� �����������, ����������� �� ������� ����� filename.

imagecreatefromwbmp() ���������� ������ ������ ��� ������. ����� ������� ��������� �� ������, ������� ������������ � �������� ��� ����������� ������. ��� ���������� ������� ��������� ������ ������� WBMP ������:

��������

������ 1. ��������� ������ ��� �������� (���������� vic@zymsys.com)

����������: ��������� WBMP �������� ������ � ��� ������, ���� PHP ��� ������������� � GD-1.8 ��� �����.

��� ����� ��� imagecreatefromxpm

(PHP 3>= 3.0.13, PHP 4 )

imagecreatefrompng — Create a new image from file or URL

Description resource imagecreatefrompng ( string filename)

imagecreatefrompng() returns an image identifier representing the image obtained from the given filename.

imagecreatefrompng() returns an empty string on failure. It also outputs an error message, which unfortunately displays as a broken link in a browser. To ease debugging the following example will produce an error PNG :

Example 1. Example to handle an error during creation (courtesy vic at zymsys dot com)

Windows versions of PHP prior to PHP 4.3.0 do not support accessing remote files via this function, even if allow_url_fopen is enabled.

Make sure when coding image serving scripts that you avoid using the full «http://» URL of the image whenever possible. Use «../imagename» etc.

Loading URL’s from your own site will double your used bandwidth, as the script grabbing the image will count against it as well as sending it to the browser.

This color table issue is actually a bit more complicated.

From my testing, it would appear that whatever colors you have specified in the color table for your picture in the first nth number of spots, those colors will automatically be given to the first «n» colors you attempt to use in your CreateImagefromPNG.

So, for example, if you need to create dynamic black and red text in your image, the first three spots in the color table for your background image should be white, black and red (in this order).

This can be a pain, but it is the only way to ensure that your images look as intended in all browsers.

I’ve noticed a couple of things with the ImageCreateFromPng function that may be useful if your having problems.

1st thing I noticed is that the PNG file you are creating from needs to be indexed and less than 256 colors.

imagecreatefromgif

(PHP 4, PHP 5, PHP 7)

imagecreatefromgif � ������� ����� ����������� �� ����� ��� URL

��������

imagecreatefromgif() ���������� ������������� �����������, ��������������� ����������� ���������� �� ����� � �������� ������.

��� ������ ������������� ������ GIF � ������, ������������ ��������� �� ������ ����������� ������ ��� ������� ������. ������ ����������� �� ����������� ����� ������������� ����, ��� ������ ������� getimagesize() .

��� ���� ������� �� ������ ������������ URL � �������� ����� �����, ���� ���� �������� ����� fopen wrappers. �������� ����� ��������� ���������� �� ����������� ����� ����� � �������� ������� fopen() . �������� ����� ������ �������������� ������� URL, �� �����������, ��������� �� ������������� � ������ ���������������� �������� � ������� �������������� ��������� � �������.

������ ����������

���� � GIF ��������.

������������ ��������

���������� ������ ����������� � ������ ������, ��� FALSE � ������ ������.

�������

������ #1 ������ ��������� ������ ��� �������� GIF

function LoadGif ( $imgname )
<
/* �������� ������� */
$im = @ imagecreatefromgif ( $imgname );

/* ���� �� ������� */
if(! $im )
<
/* ������� ������ ����������� */
$im = imagecreatetruecolor ( 150 , 30 );
$bgc = imagecolorallocate ( $im , 255 , 255 , 255 );
$tc = imagecolorallocate ( $im , 0 , 0 , 0 );

imagefilledrectangle ( $im , 0 , 0 , 150 , 30 , $bgc );

/* ������� ��������� �� ������ */
imagestring ( $im , 1 , 5 , 5 , ‘������ �������� ‘ . $imgname , $tc );
>

header ( ‘Content-Type: image/gif’ );

$img = LoadGif ( ‘bogus.image’ );

imagegif ( $img );
imagedestroy ( $img );
?>

����������� ���������� ������� ������� ����� ���-�� ��������:

����������

��������� GIF ���� ������ �� GD ���������� � ������ 1.6, � ��������� ������� � ������ 2.0.28. ��� ������� ���������� � ������������� �������.

User Contributed Notes 20 notes

An updated is_ani based on issues reported here and elsewhere

function is_ani ( $filename ) <
if(!( $fh = @ fopen ( $filename , ‘rb’ )))
return false ;
$count = 0 ;
//an animated gif contains multiple «frames», with each frame having a
//header made up of:
// * a static 4-byte sequence (\x00\x21\xF9\x04)
// * 4 variable bytes
// * a static 2-byte sequence (\x00\x2C) (some variants may use \x00\x21 ?)

// We read through the file til we reach the end of the file, or we’ve found
// at least 2 frame headers
while(! feof ( $fh ) && $count 2 ) <
$chunk = fread ( $fh , 1024 * 100 ); //read 100kb at a time
$count += preg_match_all ( ‘#\x00\x21\xF9\x04.<4>\x00(\x2C|\x21)#s’ , $chunk , $matches );
>

fclose ( $fh );
return $count > 1 ;
>
?>

A fix for the problem of the current is_ani function is to add the last 20b of the previous frame to the next one:

function is_ani ( $filename ) <
if(!( $fh = @ fopen ( $filename , ‘rb’ )))
return false ;
$count = 0 ;
//an animated gif contains multiple «frames», with each frame having a
//header made up of:
// * a static 4-byte sequence (\x00\x21\xF9\x04)
// * 4 variable bytes
// * a static 2-byte sequence (\x00\x2C) (some variants may use \x00\x21 ?)

// We read through the file til we reach the end of the file, or we’ve found
// at least 2 frame headers
$chunk = false ;
while(! feof ( $fh ) && $count 2 ) <
//add the last 20 characters from the previous string, to make sure the searched pattern is not split.
$chunk = ( $chunk ? substr ( $chunk , — 20 ) : «» ) . fread ( $fh , 1024 * 100 ); //read 100kb at a time
$count += preg_match_all ( ‘#\x00\x21\xF9\x04.<4>\x00(\x2C|\x21)#s’ , $chunk , $matches );
>

fclose ( $fh );
return $count > 1 ;
>
?>

I have written this code to detect if a gif file is animated or not. I thought I would share it :-)

function is_ani ( $filename )
<
$filecontents = file_get_contents ( $filename );

$str_loc = 0 ;
$count = 0 ;
while ( $count 2 ) # There is no point in continuing after we find a 2nd frame
<

$where1 = strpos ( $filecontents , «\x00\x21\xF9\x04» , $str_loc );
if ( $where1 === FALSE )
<
break;
>
else
<
$str_loc = $where1 + 1 ;
$where2 = strpos ( $filecontents , «\x00\x2C» , $str_loc );
if ( $where2 === FALSE )
<
break;
>
else
<
if ( $where1 + 8 == $where2 )
<
$count ++;
>
$str_loc = $where2 + 1 ;
>
>
>

if ( $count > 1 )
<
return( true );

exec ( «ls *gif» , $allfiles );
foreach ( $allfiles as $thisfile )
<
if ( is_ani ( $thisfile ))
<
echo » $thisfile is animated
\n» ;
>
else
<
echo » $thisfile is NOT animated
\n» ;
>
>
?>

It could quite easily be modified to count the number of frames if you required.

Hopefully this might save someone a headache when using functions to check for animated GIFs.

I have come across some some GIFs use the a different frame separator sequence, \x00\x21, instead of the official standard \x00\x2C. This seems to be happening with animated GIFs saved in Photoshop CS5, although I’m not quite sure if that’s where the issue is originating from.

Anyway, I’ve been using the pattern:
«#\x00\x21\xF9\x04.<4>\x00(\x2C|\x21)#s»
which seems to cover all GIFs, hopefully without misinterpreting.

Just realised that some of the animated GIFs do not contain GCE (graphic control extension). Here is the refactored is_ani() function:

/**
* Detects animated GIF from given file pointer resource or filename.
*
* @param resource|string $file File pointer resource or filename
* @return bool
*/
function is_animated_gif ( $file )
<
$fp = null ;

if ( is_string ( $file )) <
$fp = fopen ( $file , «rb» );
> else <
$fp = $file ;

/* Make sure that we are at the beginning of the file */
fseek ( $fp , 0 );
>

if ( fread ( $fp , 3 ) !== «GIF» ) <
fclose ( $fp );

return $frames > 1 ;
>

If GD doesn’t support GIFs & gif2png is not available & you are not an administrator, you can install it in your account like this:

then upload gif2png-2.4.6.tar.gz, unpack and install it:
do.php?do=tar+-xvzf+gif2png-2.4.6.tar.gz
do.php?do=gif2png-2.4.5/configure
do.php?do=make

Then remove all files except gif2png. Don’t forget to remove do.php as it is a serious security hole in your system.

esr/gif2png/
to convert gif files to png ones. It works under Unix and dos/win32/winnt and is very straightforward.
If you need to modify an user uploaded gif file to save it into your site just use this:

$path=$_FILES[«photo»][«tmp_name»];
passthru(«/usr/bin/gif2png -d -O «.$path);
$src_img=imagecreatefrompng( dirname($path).»/».basename($path, «.gif»).».png»);

This will convert the gif to a png and delete the gif file, then it will open the png with the GDlib so you can perform any operation on it.

I wanted to find out if a GIF is Black & White or Color, but I didn’t want to wait around for imagecreatefromgif() to parse a 200k file (about 1 second) to get the color map, so I wrote this function to get a list of all the colors in the GIF. Hope it is useful for you.

function getGIFColorMap ( $file )
<
$fp = fopen ( $file , ‘r’ );
$buf = fread ( $fp , 1024 );
fclose ( $fp );

// Calculate number of colors
// buf[10] is the color info byte
$color_byte = ord ( $buf [ 10 ]);
$has_color_map = ( $color_byte >> 7 ) & 1 ;
$color_res = (( $color_byte >> 4 ) & 7 ) + 1 ;
$bits_per_pixel = ( $color_byte & 7 ) + 1 ;
$color_count = 1 $bits_per_pixel ;

if (! $has_color_map ) return null ;

// buf[13] is the beginning of the color map
$color_map_index = 13 ;
$map = array();
for ( $i = 0 ; $i $color_count ; $i ++) <
$index = $color_map_index + $i * 3 ;
$r = ord ( $buf [ $index ]);
$g = ord ( $buf [ $index + 1 ]);
$b = ord ( $buf [ $index + 2 ]);
$map [ $i ] = array( $r , $g , $b );
>
return $map ;
>
?>

If anyone is looking for the Yamasoft gif conversion utility :

��� ����� ��� imagecreatefromxpm

(PHP 4 >= 4.0.1, PHP 5)

imagecreatefromxpm — Create a new image from file or URL

Description resource imagecreatefromxpm ( string filename )

imagecreatefromxpm() returns an image identifier representing the image obtained from the given filename.

Note: This function is only available if PHP is compiled with the bundled version of the GD library.

Warning

Windows versions of PHP prior to PHP 4.3.0 do not support accessing remote files via this function, even if allow_url_fopen is enabled.

imagecreatefromgif

(PHP 4, PHP 5, PHP 7)

imagecreatefromgif � ������� ����� ����������� �� ����� ��� URL

��������

imagecreatefromgif() ���������� ������������� �����������, ��������������� ����������� ���������� �� ����� � �������� ������.

��� ���� ������� �� ������ ������������ URL � �������� ����� �����, ���� ���� �������� ����� fopen wrappers. �������� ����� ��������� ���������� �� ����������� ����� ����� � �������� ������� fopen() . �������� ����� ������ �������������� ������� URL, �� �����������, ��������� �� ������������� � ������ ���������������� �������� � �������������� ��������� � ����������� (wrappers).

������ ����������

���� � GIF ��������.

������������ ��������

���������� ������ ����������� � ������ ������, ��� FALSE � ������ ������.

�������

������ #1 ������ ��������� ������ ��� �������� GIF

function LoadGif ( $imgname )
<
/* �������� ������� */
$im = @ imagecreatefromgif ( $imgname );

/* ���� �� ������� */
if(! $im )
<
/* ������� ������ ����������� */
$im = imagecreatetruecolor ( 150 , 30 );
$bgc = imagecolorallocate ( $im , 255 , 255 , 255 );
$tc = imagecolorallocate ( $im , 0 , 0 , 0 );

imagefilledrectangle ( $im , 0 , 0 , 150 , 30 , $bgc );

/* ������� ��������� �� ������ */
imagestring ( $im , 1 , 5 , 5 , ‘������ �������� ‘ . $imgname , $tc );
>

header ( ‘Content-Type: image/gif’ );

$img = LoadGif ( ‘bogus.image’ );

imagegif ( $img );
imagedestroy ( $img );
?>

����������� ���������� ������� ������� ����� ���-�� ��������:

����������

��������� GIF ���� ������ �� GD ���������� � ������ 1.6, � ��������� ������� � ������ 2.0.28. ��� ������� ���������� � ������������� �������.

��� ������ ������������� ������ GIF � ������, ������������ ��������� �� ������ ����������� ������ ��� ������� ������.

������ PHP ��� Windows �� PHP 4.3.0 �� ������������ ����������� ������������� ��������� ������ ���� �������� ���� � ��� ������, ���� �������� ����� allow_url_fopen.

����������

function myImageCreateFromGif ( $file_or_url ) <

# if this is a url, use fopen to get the file data, then
# save it to a dummy file
if ( preg_match ( «/(http|ftp):\/\//i» , $file_or_url )) <
# open the file using fopen, which supports remote URLs
$input = fopen ( $file_or_url , «rb» );

# read the contents of the file
# will accept files up to 10Mb, but will probably get
# and EOF before that, we have to do it this way because
# filesize isn’t designed to work with URLs. sigh.
$image_data = fread ( $input , 10000000 );

# write the contents to a dummy file
$output = fopen ( «$dummy_file» , «wb» );
fwrite ( $output , $image_data );
fclose ( $output );

# create the gif from the dummy file
$image = ImageCreateFromGif ( $dummy_file );

# get rid of the dummy file
unlink ( $dummy_file );

# if it’s not a URL, we can simply open the image directly
else <
$image = ImageCreateFromGif ( $file_or_url );
>

if ( $image == «» || $image == 0 ) <
print «

No Image data was returned.

\n» ;
>
else <
header ( «Content-Type: image/gif\n\n» );
ImageGif ( $image );
>

esr/gif2png/
to convert gif files to png ones. It works under Unix and dos/win32/winnt and is very straightforward.
If you need to modify an user uploaded gif file to save it into your site just use this:

$path=$_FILES[«photo»][«tmp_name»];
passthru(«/usr/bin/gif2png -d -O «.$path);
$src_img=imagecreatefrompng( dirname($path).»/».basename($path, «.gif»).».png»);

This will convert the gif to a png and delete the gif file, then it will open the png with the GDlib so you can perform any operation on it.

If GD doesn’t support GIFs & gif2png is not available & you are not an administrator, you can install it in your account like this:

create do.php:
global $do ;
passthru ( $do );
?>

then upload gif2png-2.4.6.tar.gz, unpack and install it:
do.php?do=tar+-xvzf+gif2png-2.4.6.tar.gz
do.php?do=gif2png-2.4.5/configure
do.php?do=make

Then remove all files except gif2png. Don’t forget to remove do.php as it is a serious security hole in your system.

FreeBSD users are lucky to have the option of compiling GIF support in GD2.x through the ports system.
All you need to do is to export the «WITH_LZW=yes» global variable when compiling the graphics/gd2 port, e.g.:

# cd /usr/ports/graphics/gd2
# export WITH_LZW=yes
# make && make install

Then recompile and (re)install the www/mod_php4 port and you are in business. :)

For users who just want GIF read (not write) support but:
1) Don’t want to patch GD libs
2) Don’t want to recompile something
3) Don’t have permissions to install conversion packages
4) Any other reason.

I created a small php script (around 25KB) which lets you load a GIF from a file (you even can specify the image index on animated GIFs) and then convert it to a PNG or BMP file.

If I take one example:

$gif = gif_loadFile ( «./test.gif» );

if( $gif ) <
// GIF file successfully opened
if( gif_outputAsPNG ( $gif , «./test.png» )) <
// Now, just use ImageCreateFromPng.
$img = ImageCreateFromPng ( «./test.png» );

if( $img ) <
header ( «Content-Type: image/jpeg» );
ImageJPEG ( $img );
ImageDestroy ( $img );
>
else <
// Could NOT open PNG
>
>
else <
// Could NOT convert GIF to PNG.
>
>
else <
// GIF not loaded.
>
?>

Of course, it’s slower than using appropriate software and/or libraries but it’s quite useful for reading occasionaly some GIF files.

You’ll find the gif.php source code at: http://www.yamasoft.com/php-gif.zip

After hours of search, I’ve finally found a program which can convert JPG to GIF.
IJG — The Independent JPEG Group’s JPEG software
Version 6 which support GIF (read and write with LZW)
and the version 6b which support GIF (write only without LZW)

The name of the file is: jpegsrc.v6.tar.gz

re: 09-May-2002 11:31

Seems gif2png is no longer at http://www.tuxedo.org/

esr/gif2png/
I found a Win32 version at http://www.r1ch.net/stuff/gif2png/
(for the Unix and source, see http://catb.org/

In Win32,
passthru(«gif2png $filename»);
works fine if gif2png.exe is in the path.
It will overwrite the file with .png extension, so be careful,or use temp files as in the post referenced above (without the -O; type «gif2png» at the command line for the options).

I had a problem with exceeding the default 30 second execution time limit in PHP, so I added this line
set_time_limit(0); // some odd gifs take a long time (example, a 25K gif, 700×700, mostly blank)

I just installed gif2png on my server, and it took a little research on my part to figure out that this.

passthru(«$path/gif2png -O $image_path/image.gif»)

will not work if safe mode is on. If you’re on a shared server, it probably is. You don’t need to turn safe mode off, however, just set the safe_mode_exec_dir variable in your php.ini file to the directory where you installed gif2png. Then you’ll be able to execute the program from your PHP script.

thanks yamasoft for the gif to png lib. it works! but, there is one bug. i changed line 1003 to this:

if(isset($this->m_img->m_bTrans) && $this->m_img->m_bTrans && ($nColors > 0)) <

because i was getting an error that m_bTrans is undefined. i think this is because my gif has no transparency. after i updated this line, there were no problems.

If anyone is looking for the Yamasoft gif conversion utility :

Although Yamasoft’s website is long gone, the code can be found on the following websites :
http://www.fpdf.org/phorum/read.php?f=1&i=9418&t=7568#9418

I have written this code to detect if a gif file is animated or not. I thought I would share it :-)

function is_ani ( $filename )
<
$filecontents = file_get_contents ( $filename );

$str_loc = 0 ;
$count = 0 ;
while ( $count 2 ) # There is no point in continuing after we find a 2nd frame
<

$where1 = strpos ( $filecontents , «\x00\x21\xF9\x04» , $str_loc );
if ( $where1 === FALSE )
<
break;
>
else
<
$str_loc = $where1 + 1 ;
$where2 = strpos ( $filecontents , «\x00\x2C» , $str_loc );
if ( $where2 === FALSE )
<
break;
>
else
<
if ( $where1 + 8 == $where2 )
<
$count ++;
>
$str_loc = $where2 + 1 ;
>
>
>

if ( $count > 1 )
<
return( true );

exec ( «ls *gif» , $allfiles );
foreach ( $allfiles as $thisfile )
<
if ( is_ani ( $thisfile ))
<
echo «$thisfile is animated
\n» ;
>
else
<
echo «$thisfile is NOT animated
\n» ;
>
>
?>

It could quite easily be modified to count the number of frames if you required.

I wanted to find out if a GIF is Black & White or Color, but I didn’t want to wait around for imagecreatefromgif() to parse a 200k file (about 1 second) to get the color map, so I wrote this function to get a list of all the colors in the GIF. Hope it is useful for you.

function getGIFColorMap ( $file )
<
$fp = fopen ( $file , ‘r’ );
$buf = fread ( $fp , 1024 );
fclose ( $fp );

// Calculate number of colors
// buf[10] is the color info byte
$color_byte = ord ( $buf [ 10 ]);
$has_color_map = ( $color_byte >> 7 ) & 1 ;
$color_res = (( $color_byte >> 4 ) & 7 ) + 1 ;
$bits_per_pixel = ( $color_byte & 7 ) + 1 ;
$color_count = 1 $bits_per_pixel ;

if (! $has_color_map ) return null ;

// buf[13] is the beginning of the color map
$color_map_index = 13 ;
$map = array();
for ( $i = 0 ; $i $color_count ; $i ++) <
$index = $color_map_index + $i * 3 ;
$r = ord ( $buf [ $index ]);
$g = ord ( $buf [ $index + 1 ]);
$b = ord ( $buf [ $index + 2 ]);
$map [ $i ] = array( $r , $g , $b );
>
return $map ;
>
?>

Hopefully this might save someone a headache when using functions to check for animated GIFs.

I have come across some some GIFs use the a different frame separator sequence, \x00\x21, instead of the official standard \x00\x2C. This seems to be happening with animated GIFs saved in Photoshop CS5, although I’m not quite sure if that’s where the issue is originating from.

Anyway, I’ve been using the pattern:
«#\x00\x21\xF9\x04.<4>\x00(\x2C|\x21)#s»
which seems to cover all GIFs, hopefully without misinterpreting.

An updated is_ani based on issues reported here and elsewhere

function is_ani ( $filename ) <
if(!( $fh = @ fopen ( $filename , ‘rb’ )))
return false ;
$count = 0 ;
//an animated gif contains multiple «frames», with each frame having a
//header made up of:
// * a static 4-byte sequence (\x00\x21\xF9\x04)
// * 4 variable bytes
// * a static 2-byte sequence (\x00\x2C) (some variants may use \x00\x21 ?)

// We read through the file til we reach the end of the file, or we’ve found
// at least 2 frame headers
while(! feof ( $fh ) && $count 2 ) <
$chunk = fread ( $fh , 1024 * 100 ); //read 100kb at a time
$count += preg_match_all ( ‘#\x00\x21\xF9\x04.<4>\x00(\x2C|\x21)#s’ , $chunk , $matches );
>

fclose ( $fh );
return $count > 1 ;
>
?>

imagecreatefrompng

(PHP 4, PHP 5, PHP 7)

imagecreatefrompng � ������� ����� ����������� �� ����� ��� URL

��������

imagecreatefrompng() ���������� ������������� �����������, ��������������� ����������� ���������� �� ����� � �������� ������.

��� ���� ������� �� ������ ������������ URL � �������� ����� �����, ���� ���� �������� ����� fopen wrappers. �������� ����� ��������� ���������� �� ����������� ����� ����� � �������� ������� fopen() . �������� ����� ������ �������������� ������� URL, �� �����������, ��������� �� ������������� � ������ ���������������� �������� � ������� �������������� ��������� � �������.

������ ����������

���� � ����������� PNG.

������������ ��������

���������� ������ ����������� � ������ ������, ��� FALSE � ������ ������.

�������

������ #1 ������ ��������� ������ ��� �������� PNG

function LoadPNG ( $imgname )
<
/* �������� ������� */
$im = @ imagecreatefrompng ( $imgname );

/* ���� �� ������� */
if(! $im )
<
/* ������� ������ ����������� */
$im = imagecreatetruecolor ( 150 , 30 );
$bgc = imagecolorallocate ( $im , 255 , 255 , 255 );
$tc = imagecolorallocate ( $im , 0 , 0 , 0 );

imagefilledrectangle ( $im , 0 , 0 , 150 , 30 , $bgc );

/* ������� ��������� �� ������ */
imagestring ( $im , 1 , 5 , 5 , ‘������ �������� ‘ . $imgname , $tc );
>

header ( ‘Content-Type: image/png’ );

$img = LoadPNG ( ‘bogus.image’ );

imagepng ( $img );
imagedestroy ( $img );
?>

����������� ���������� ������� ������� ����� ���-�� ��������:

User Contributed Notes 6 notes

If you’re trying to load a translucent png-24 image but are finding an absence of transparency (like it’s black), you need to enable alpha channel AND save the setting. I’m new to GD and it took me almost two hours to figure this out.

= imageCreateFromPng ( $strImagePath );
imageAlphaBlending ( $imgPng , true );
imageSaveAlpha ( $imgPng , true );

/* Output image to browser */
header ( «Content-type: image/png» );
imagePng ( $imgPng );
?>

I had the same problem as jboyd1189 at yahoo dot com but I solve d it allocating more memory dynamically.

Usually the memory_limit var on php.ini is set to 8M. Unfortunately, the required amount of memory to manage a PNG image about 1000×1000 could be bigger !

The approach I used to solve the problem is:

1-Calculate the memory required by the image
2-Set the new memory_limit value
3-Create the PNG image and thumbnail
4-Restore the original value

1-The following value works for me:
$required_memory = Round($width * $height * $size[‘bits’]);

2-Use somthing like:
$new_limit=memory_get_usage() + $required_memory;
ini_set(«memory_limit», $new_limit);

When using imagecreatepng with alpha blending you will lose the blending.

To over come this use something like the following
= imagecreatetruecolor ( $width , $height );
$srcimage = imagecreatefrompng ( $src );
imagecopyresampled ( $dstimage , $srcimage , 0 , 0 , 0 , 0 , $width , $height , $width , $height );
?>
Where $width and $height are the width and height of the $src image.

This will create a true colour image then copy the png image to this true colour image and retain alpha blending.

I have this code:

if (exif_imagetype($this->img_name) == IMAGETYPE_PNG) <
try <

$this->image = imagecreatefrompng($this->img_name);
Error::log(‘It is a png: ‘.$this->img_name);
> catch (Exception $e) <
echo «The image file has some strange charachters. Probably not a png image?»;
$this->image = »;
$this->img_name = »;
>
>

And I get this error in the error.log:
PHP Unknown error: imagecreatefrompng(): gd-png: fatal libpng error: Extra compressed data\n in Unknown on line 0

The file that I try to open is a generated .png image which I can open from gimp and Geeqie.

What is the problem? Could you please help me?

Илон Маск рекомендует:  Полоски при наведении
Понравилась статья? Поделиться с друзьями:
Кодинг, CSS и SQL
Warning