content type image png

(PHP 4, PHP 5, PHP 7)

imagepng — Вывод PNG изображения в броузер или файл

Описание

Список параметров

Ресурс изображения, полученный одной из функций создания изображений, например, такой как imagecreatetruecolor() .

Путь для сохранения файла. Если не установлен или равен NULL , изображение будет выведено в поток вывода в бинарном виде.

Недопустимо передавать NULL , если не используются аргументы quality и filters .

Степень сжатия: от 0 (нет сжатия) до 9.

Позволяет уменьшить размер PNG файла. Это битовая маска, значением которой может быть комбинация констант PNG_FILTER_XXX. Для включения или выключения всех фильтров удобно воспользоваться константами PNG_NO_FILTER или PNG_ALL_FILTERS соответственно.

Возвращаемые значения

Возвращает TRUE в случае успешного завершения или FALSE в случае возникновения ошибки.

Список изменений

Версия Описание
5.1.3 Добавлен аргумент filters .
5.1.2 Добавлен аргумент quality .

Примеры

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

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

Смотрите также

  • imagegif() — Выводит изображение в браузер или пишет в файл
  • imagewbmp() — Выводит изображение в браузер или пишет в файл
  • imagejpeg() — Выводит изображение в браузер или пишет в файл
  • imagetypes() — Возвращает список типов изображений, поддерживаемых PHP сборкой
  • imagesavealpha() — Установка флага сохранения всей информации альфа компонента (в противовес одноцветной прозрачности) и сохранение PNG изображения

Internet Media Types [1] — типы данных, которые могут быть переданы посредством сети интернет с применением стандарта MIME. Ниже приведён список MIME-заголовков и расширений файлов.

Содержание

Общие типы [ править | править код ]

Согласно RFC 2045, RFC 2046, RFC 4288, RFC 4289 и RFC 4855 [2] выделяются следующие базовые типы передаваемых данных:

Внутренний формат прикладной программы

  • application/atom+xml : Atom
  • application/EDI-X12 : EDIX12 (RFC 1767)
  • application/EDIFACT : EDIEDIFACT (RFC 1767)
  • application/json : JavaScript Object Notation JSON (RFC 4627)
  • application/javascript : JavaScript (RFC 4329)
  • application/octet-stream : двоичный файл без указания формата (RFC 2046) [3]
  • application/ogg : Ogg (RFC 5334)
  • application/pdf : Portable Document Format, PDF (RFC 3778)
  • application/postscript : PostScript (RFC 2046)
  • application/soap+xml : SOAP (RFC 3902)
  • application/font-woff : Web Open Font Format[4]
  • application/xhtml+xml : XHTML (RFC 3236)
  • application/xml-dtd : DTD (RFC 3023)
  • application/xop+xml :XOP
  • application/zip : ZIP[5]
  • application/gzip : Gzip
  • application/x-bittorrent : BitTorrent
  • application/x-tex : TeX
  • application/xml : XML
  • application/msword : DOC

audio [ править | править код ]

  • audio/basic : mulaw аудио, 8 кГц, 1 канал (RFC 2046)
  • audio/L24 : 24bit Linear PCM аудио, 8-48 кГц, 1-N каналов (RFC 3190)
  • audio/mp4 : MP4
  • audio/aac : AAC
  • audio/mpeg : MP3 или др. MPEG (RFC 3003)
  • audio/ogg : OggVorbis, Speex, Flac или др. аудио (RFC 5334)
  • audio/vorbis : Vorbis (RFC 5215)
  • audio/x-ms-wma : Windows Media Audio[6]
  • audio/x-ms-wax : Windows Media Audio перенаправление
  • audio/vnd.rn-realaudio : RealAudio[7]
  • audio/vnd.wave : WAV(RFC 2361)
  • audio/webm : WebM

image [ править | править код ]

message [ править | править код ]

model [ править | править код ]

  • model/example : (RFC 4735)
  • model/iges : IGS файлы, IGES файлы (RFC 2077)
  • model/mesh : MSH файлы, MESH файлы (RFC 2077), SILO файлы
  • model/vrml : WRL файлы, VRML файлы (RFC 2077)
  • model/x3d+binary : X3DISO стандарт для 3D компьютерной графики, X3DB файлы
  • model/x3d+vrml : X3DISO стандарт для 3D компьютерной графики, X3DV VRML файлы
  • model/x3d+xml : X3DISO стандарт для 3D компьютерной графики, X3D XML файлы

multipart [ править | править код ]

  • multipart/mixed : MIMEE-mail (RFC 2045 и RFC 2046)
  • multipart/alternative : MIMEE-mail (RFC 2045 и RFC 2046)
  • multipart/related : MIMEE-mail (RFC 2387 и используемое MHTML (HTML mail))
  • multipart/form-data : MIMEWebform (RFC 2388)
  • multipart/signed : (RFC 1847)
  • multipart/encrypted : (RFC 1847)

text [ править | править код ]

  • text/cmd : команды
  • text/css : Cascading Style Sheets (RFC 2318)
  • text/csv : CSV (RFC 4180)
  • text/html : HTML (RFC 2854)
  • text/javascript (Obsolete): JavaScript (RFC 4329)
  • text/plain : текстовые данные (RFC 2046 и RFC 3676)
  • text/php : Скрипт языка PHP
  • text/xml : Extensible Markup Language (RFC 3023)
  • text/markdown : файл языка разметки Markdown (RFC 7763)
  • text/cache-manifest : файл манифеста(RFC 2046)

video [ править | править код ]

vnd [ править | править код ]

  • application/vnd.oasis.opendocument.text : OpenDocument[14]
  • application/vnd.oasis.opendocument.spreadsheet : OpenDocument[15]
  • application/vnd.oasis.opendocument.presentation : OpenDocument[16]
  • application/vnd.oasis.opendocument.graphics : OpenDocument[17]
  • application/vnd.ms-excel : Microsoft Excel файлы
  • application/vnd.openxmlformats-officedocument.spreadsheetml.sheet : Microsoft Excel 2007 файлы
  • application/vnd.ms-powerpoint : Microsoft Powerpoint файлы
  • application/vnd.openxmlformats-officedocument.presentationml.presentation : Microsoft Powerpoint 2007 файлы
  • application/msword : Microsoft Word файлы
  • application/vnd.openxmlformats-officedocument.wordprocessingml.document : Microsoft Word 2007 файлы
  • application/vnd.mozilla.xul+xml : MozillaXUL файлы
  • application/vnd.google-earth.kml+xml : KML файлы (например, для Google Earth)

x [ править | править код ]

  • application/x-www-form-urlencoded Form Encoded Data [18]
  • application/x-dvi : DVI
  • application/x-latex : LaTeX файлы
  • application/x-font-ttf : TrueType (не зарегистрированный MIME-тип, но наиболее часто используемый)
  • application/x-shockwave-flash : Adobe Flash[19] и [20]
  • application/x-stuffit : StuffIt
  • application/x-rar-compressed : RAR
  • application/x-tar : Tarball
  • text/x-jquery-tmpl : jQuery
  • application/x-javascript :

x-pkcs [ править | править код ]

  • application/x-pkcs12 : p12 файлы
  • application/x-pkcs12 : pfx файлы
  • application/x-pkcs7-certificates : p7b файлы
  • application/x-pkcs7-certificates : spc файлы
  • application/x-pkcs7-certreqresp : p7r файлы
  • application/x-pkcs7-mime : p7c файлы
  • application/x-pkcs7-mime : p7m файлы
  • application/x-pkcs7-signature : p7s файлы

I want to use imagecreatefromjpeg , imagecreatetruecolor , imagecopyresized and imagejpeg while making use of the echo » «; etc.

For some reason I get «The image could not be displayed because there were errors on the page» until I comment out header(‘Content-type: image/png’); and then I just get a picture of a broken picture, like a torn page.

All I’ve seen is that I can’t have header(‘Content-type: image/png’); and html in the same .php file. If that’s the case can anybody tell me how to resize an image for a thumbnail gallery while still having html in a .php file?

Thanks in advance.

closed as unclear what you’re asking by John Conde, andrewsi, Kevin, Yuliam Chandra, Divi Sep 11 ’14 at 3:19

Please clarify your specific problem or add additional details to highlight exactly what you need. As it’s currently written, it’s hard to tell exactly what you’re asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

3 Answers 3

You are mixing up two different things.

A webpage with an image on it, does not contain that image in general. Instead, it often refers to an external source. I said in general, because, yes, an image can be embedded in an HTML page, see below.

You have two options:

You can create an apart PHP file where you create the image and output its bytes. In your HTML code, you refer to that image:

page.html:

myimage.php:

Or you can embed the image in your HTML file, using base64 encoding:

The second option is suitable for smaller images, since the base64 encoded string will produce large portions of text.

If I understand it correctly, you want to read images from a directory and resize them to the same size, using them as thumbnails?

What you might just want to do is create a PHP file where you read a source image and give them the same size.

Just like ‘normal’ PHP files, PHP can do something with the request parameters you give. Perhaps you’ve ever seen this:

That string behind the question mark ( key=value&anotherkey=anothervalue ) is the query string. PHP can do something with the values:

Now we can just do the same when creating an image. You don’t have to make twenty PHP files with almost the same code, but just a single file which reads a file (you name it) and resizes it to the specified width (you name it) and height (you name it).

Оцените статью