- Saved searches
- Use saved searches to filter your results more quickly
- License
- jindrapetrik/php-bmp
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- imagebmp
- Список параметров
- Возвращаемые значения
- Список изменений
- Примеры
- User Contributed Notes
- imagecreate
- Список параметров
- Возвращаемые значения
- Список изменений
- Примеры
- Смотрите также
- User Contributed Notes 20 notes
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
License
jindrapetrik/php-bmp
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
Bitmap image support for PHP
This started because in the past there was no support for generating/reading Bitmap (BMP) files in PHP.
PHP has built-in function imagecreatefrombmp and imagebmp since version 7.2, but as of my testing — not all BMP file formats are supported.
This project contains own implementation of imagecreatefrombmp and imagebmp functions.
//include lib first require_once 'bmp.php'; //for PHP before 7.2 $img = imagecreatefrombmp("file.bmp"); //. header("Content-type: image/bmp"); imagebmp($img); //for PHP 7.2 and newer (if you want to use new BMP file formats) use Com\Jpexs\Image\Bitmap; $bmp = new Bitmap(); $img = $bmp->imageCreateFromBmp("file.bmp"); //. header("Content-type: image/bmp"); $bmp->imageBmp($img);
BI_RGB, BI_RLE8, BI_RLE4, BI_BITFIELDS
The library is licensed under GNU/LGPL v2.1
Changes in versions are logged in the file CHANGELOG.md
imagebmp
Выводит или сохраняет BMP-версию заданного изображения ( image ).
Список параметров
Объект GdImage , возвращаемый одной из функций создания изображений, например, такой как imagecreatetruecolor() .
Путь, или открытый потоковый ресурс (который автоматически закрывается после завершения функции), для сохранения файла. Если не установлен или равен null , изображение будет выведено в поток вывода в бинарном виде.
Замечание:
null недействителен, если аргумент compressed не используется.
Должен ли BMP быть сжат с кодировкой длин серий (RLE), или нет.
Возвращаемые значения
Возвращает true в случае успешного выполнения или false в случае возникновения ошибки.
Однако, если libgd не может вывести изображения, эта функция вернёт true .
Список изменений
Версия | Описание |
---|---|
8.0.0 | image теперь ожидает экземпляр GdImage ; ранее ожидался корректный gd ресурс ( resource ). |
8.0.0 | Тип параметра compressed теперь логическое значение ( bool ); ранее был целым числом ( int ). |
Примеры
Пример #1 Сохранение BMP-файла
// Создайте пустое изображение и добавьте текст
$im = imagecreatetruecolor ( 120 , 20 );
$text_color = imagecolorallocate ( $im , 233 , 14 , 91 );
?php
imagestring ( $im , 1 , 5 , 5 , ‘BMP with PHP’ , $text_color );
// Сохранить изображение
imagebmp ( $im , ‘php.bmp’ );
// Освободить память
imagedestroy ( $im );
?>
User Contributed Notes
- Функции GD и функции для работы с изображениями
- gd_info
- getimagesize
- getimagesizefromstring
- image_type_to_extension
- image_type_to_mime_type
- image2wbmp
- imageaffine
- imageaffinematrixconcat
- imageaffinematrixget
- imagealphablending
- imageantialias
- imagearc
- imageavif
- imagebmp
- imagechar
- imagecharup
- imagecolorallocate
- imagecolorallocatealpha
- imagecolorat
- imagecolorclosest
- imagecolorclosestalpha
- imagecolorclosesthwb
- imagecolordeallocate
- imagecolorexact
- imagecolorexactalpha
- imagecolormatch
- imagecolorresolve
- imagecolorresolvealpha
- imagecolorset
- imagecolorsforindex
- imagecolorstotal
- imagecolortransparent
- imageconvolution
- imagecopy
- imagecopymerge
- imagecopymergegray
- imagecopyresampled
- imagecopyresized
- imagecreate
- imagecreatefromavif
- imagecreatefrombmp
- imagecreatefromgd2
- imagecreatefromgd2part
- imagecreatefromgd
- imagecreatefromgif
- imagecreatefromjpeg
- imagecreatefrompng
- imagecreatefromstring
- imagecreatefromtga
- imagecreatefromwbmp
- imagecreatefromwebp
- imagecreatefromxbm
- imagecreatefromxpm
- imagecreatetruecolor
- imagecrop
- imagecropauto
- imagedashedline
- imagedestroy
- imageellipse
- imagefill
- imagefilledarc
- imagefilledellipse
- imagefilledpolygon
- imagefilledrectangle
- imagefilltoborder
- imagefilter
- imageflip
- imagefontheight
- imagefontwidth
- imageftbbox
- imagefttext
- imagegammacorrect
- imagegd2
- imagegd
- imagegetclip
- imagegetinterpolation
- imagegif
- imagegrabscreen
- imagegrabwindow
- imageinterlace
- imageistruecolor
- imagejpeg
- imagelayereffect
- imageline
- imageloadfont
- imageopenpolygon
- imagepalettecopy
- imagepalettetotruecolor
- imagepng
- imagepolygon
- imagerectangle
- imageresolution
- imagerotate
- imagesavealpha
- imagescale
- imagesetbrush
- imagesetclip
- imagesetinterpolation
- imagesetpixel
- imagesetstyle
- imagesetthickness
- imagesettile
- imagestring
- imagestringup
- imagesx
- imagesy
- imagetruecolortopalette
- imagettfbbox
- imagettftext
- imagetypes
- imagewbmp
- imagewebp
- imagexbm
- iptcembed
- iptcparse
- jpeg2wbmp
- png2wbmp
imagecreate
imagecreate() возвращает идентификатор изображения, представляющего из себя пустое изображение заданного размера.
Мы рекомендуем использовать функцию imagecreatetruecolor() вместо imagecreate() , так как она обрабатывает изображения с максимально возможным качеством. Если необходимо вывести палитру изображения, то imagetruecolortopalette() необходимо вызвать непосредственно перед сохранением изображения с помощью imagepng() или imagegif() .
Список параметров
Возвращаемые значения
Возвращает объект изображения в случае успешного выполнения или false в случае возникновения ошибки.
Список изменений
Версия Описание 8.0.0 В случае успешного выполнения функция теперь возвращает экземпляр GDImage ; ранее возвращался ресурс ( resource ). Примеры
Пример #1 Создание нового GD потока изображения и вывод изображения.
header ( «Content-Type: image/png» );
$im = @ imagecreate ( 110 , 20 )
or die( «Невозможно создать поток изображения» );
$background_color = imagecolorallocate ( $im , 0 , 0 , 0 );
$text_color = imagecolorallocate ( $im , 233 , 14 , 91 );
imagestring ( $im , 1 , 5 , 5 , «A Simple Text String» , $text_color );
imagepng ( $im );
imagedestroy ( $im );
?>?phpРезультатом выполнения данного примера будет что-то подобное:
Смотрите также
User Contributed Notes 20 notes
to create an image from a BMP file, I made this function, that return a resource like the others ImageCreateFrom function:
function ImageCreateFromBMP ( $filename )
//Ouverture du fichier en mode binaire
if (! $f1 = fopen ( $filename , «rb» )) return FALSE ;//1 : Chargement des ent?tes FICHIER
$FILE = unpack ( «vfile_type/Vfile_size/Vreserved/Vbitmap_offset» , fread ( $f1 , 14 ));
if ( $FILE [ ‘file_type’ ] != 19778 ) return FALSE ;//2 : Chargement des ent?tes BMP
$BMP = unpack ( ‘Vheader_size/Vwidth/Vheight/vplanes/vbits_per_pixel’ .
‘/Vcompression/Vsize_bitmap/Vhoriz_resolution’ .
‘/Vvert_resolution/Vcolors_used/Vcolors_important’ , fread ( $f1 , 40 ));
$BMP [ ‘colors’ ] = pow ( 2 , $BMP [ ‘bits_per_pixel’ ]);
if ( $BMP [ ‘size_bitmap’ ] == 0 ) $BMP [ ‘size_bitmap’ ] = $FILE [ ‘file_size’ ] — $FILE [ ‘bitmap_offset’ ];
$BMP [ ‘bytes_per_pixel’ ] = $BMP [ ‘bits_per_pixel’ ]/ 8 ;
$BMP [ ‘bytes_per_pixel2’ ] = ceil ( $BMP [ ‘bytes_per_pixel’ ]);
$BMP [ ‘decal’ ] = ( $BMP [ ‘width’ ]* $BMP [ ‘bytes_per_pixel’ ]/ 4 );
$BMP [ ‘decal’ ] -= floor ( $BMP [ ‘width’ ]* $BMP [ ‘bytes_per_pixel’ ]/ 4 );
$BMP [ ‘decal’ ] = 4 -( 4 * $BMP [ ‘decal’ ]);
if ( $BMP [ ‘decal’ ] == 4 ) $BMP [ ‘decal’ ] = 0 ;//3 : Chargement des couleurs de la palette
$PALETTE = array();
if ( $BMP [ ‘colors’ ] < 16777216 )
$PALETTE = unpack ( ‘V’ . $BMP [ ‘colors’ ], fread ( $f1 , $BMP [ ‘colors’ ]* 4 ));
>//4 : Cr?ation de l’image
$IMG = fread ( $f1 , $BMP [ ‘size_bitmap’ ]);
$VIDE = chr ( 0 );$res = imagecreatetruecolor ( $BMP [ ‘width’ ], $BMP [ ‘height’ ]);
$P = 0 ;
$Y = $BMP [ ‘height’ ]- 1 ;
while ( $Y >= 0 )
$X = 0 ;
while ( $X < $BMP [ 'width' ])
if ( $BMP [ ‘bits_per_pixel’ ] == 24 )
$COLOR = unpack ( «V» , substr ( $IMG , $P , 3 ). $VIDE );
elseif ( $BMP [ ‘bits_per_pixel’ ] == 16 )
<
$COLOR = unpack ( «n» , substr ( $IMG , $P , 2 ));
$COLOR [ 1 ] = $PALETTE [ $COLOR [ 1 ]+ 1 ];
>
elseif ( $BMP [ ‘bits_per_pixel’ ] == 8 )
<
$COLOR = unpack ( «n» , $VIDE . substr ( $IMG , $P , 1 ));
$COLOR [ 1 ] = $PALETTE [ $COLOR [ 1 ]+ 1 ];
>
elseif ( $BMP [ ‘bits_per_pixel’ ] == 4 )
$COLOR = unpack ( «n» , $VIDE . substr ( $IMG , floor ( $P ), 1 ));
if (( $P * 2 )% 2 == 0 ) $COLOR [ 1 ] = ( $COLOR [ 1 ] >> 4 ) ; else $COLOR [ 1 ] = ( $COLOR [ 1 ] & 0x0F );
$COLOR [ 1 ] = $PALETTE [ $COLOR [ 1 ]+ 1 ];
>
elseif ( $BMP [ ‘bits_per_pixel’ ] == 1 )
$COLOR = unpack ( «n» , $VIDE . substr ( $IMG , floor ( $P ), 1 ));
if (( $P * 8 )% 8 == 0 ) $COLOR [ 1 ] = $COLOR [ 1 ] >> 7 ;
elseif (( $P * 8 )% 8 == 1 ) $COLOR [ 1 ] = ( $COLOR [ 1 ] & 0x40 )>> 6 ;
elseif (( $P * 8 )% 8 == 2 ) $COLOR [ 1 ] = ( $COLOR [ 1 ] & 0x20 )>> 5 ;
elseif (( $P * 8 )% 8 == 3 ) $COLOR [ 1 ] = ( $COLOR [ 1 ] & 0x10 )>> 4 ;
elseif (( $P * 8 )% 8 == 4 ) $COLOR [ 1 ] = ( $COLOR [ 1 ] & 0x8 )>> 3 ;
elseif (( $P * 8 )% 8 == 5 ) $COLOR [ 1 ] = ( $COLOR [ 1 ] & 0x4 )>> 2 ;
elseif (( $P * 8 )% 8 == 6 ) $COLOR [ 1 ] = ( $COLOR [ 1 ] & 0x2 )>> 1 ;
elseif (( $P * 8 )% 8 == 7 ) $COLOR [ 1 ] = ( $COLOR [ 1 ] & 0x1 );
$COLOR [ 1 ] = $PALETTE [ $COLOR [ 1 ]+ 1 ];
>
else
return FALSE ;
imagesetpixel ( $res , $X , $Y , $COLOR [ 1 ]);
$X ++;
$P += $BMP [ ‘bytes_per_pixel’ ];
>
$Y —;
$P += $BMP [ ‘decal’ ];
>//Fermeture du fichier
fclose ( $f1 );