imagepng php черный фон
imagecreatefrompng
(PHP 4, PHP 5, PHP 7, PHP 8)
imagecreatefrompng — Создаёт новое изображение из файла или URL
Описание
imagecreatefrompng() возвращает идентификатор изображения, представляющего изображение полученное из файла с заданным именем.
Список параметров
Путь к изображению PNG.
Возвращаемые значения
Возвращает объект изображения в случае успешного выполнения или false в случае возникновения ошибки.
Список изменений
Версия | Описание |
---|---|
8.0.0 | В случае успешного выполнения функция теперь возвращает экземпляр GDImage ; ранее возвращался ресурс ( resource ). |
Примеры
Пример #1 Пример обработки ошибки при загрузке PNG
header ( ‘Content-Type: image/png’ );
$img = LoadPNG ( ‘bogus.image’ );
Результатом выполнения данного примера будет что-то подобное:
User Contributed Notes 7 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.
I had the same problem as jboyd1189 at yahoo dot com but I solve d it allocating more memory dynamically.
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
Because gd and imagick do not support animated PNG (at this moment), i wrote a simple function to determine if given PNG is APNG or not. It does not validate PNG, only checks whenever «acTL» chunk appears before «IDAT» like the specification says: https://wiki.mozilla.org/APNG_Specification
When using imagecreatepng with alpha blending you will lose the blending.
This will create a true colour image then copy the png image to this true colour image and retain alpha blending.
imagepng
(PHP 4, PHP 5, PHP 7, PHP 8)
imagepng — Вывод PNG изображения в браузер или файл
Описание
Список параметров
Параметр filters игнорируется системной библиотекой libgd.
Возвращаемые значения
Возвращает true в случае успешного выполнения или false в случае возникновения ошибки.
Список изменений
Версия | Описание |
---|---|
8.0.0 | image теперь ожидает экземпляр GdImage ; ранее ожидался ресурс ( resource ). |
Примеры
header ( ‘Content-Type: image/png’ );
Смотрите также
User Contributed Notes 34 notes
The name «quality» for the compression parameter is quite misleading, as png compression is always lossless. The trade off is between speed and filesize, it cannot affect quality.
Here’s something I found at stackoverflow; I haven’t checked it, but if it is correct it should definitely included in the documentation:
—
from php source (gd.h):
Regarding suggestions to rescale the 0-99 quality range of jpeg into the 0-9 range of png, note that for jpeg 99 is minimum compression (maximum quality) while for png 9 is maximum compression (quality doesn’t change).
«Tip: As with anything that outputs its result directly to the browser, you can use the output-control functions (http://www.php.net/manual/en/ref.outcontrol.php) to capture the output of this function, and save it in a string (for example).»
If you want to open a png image with alpha blending, you need to do something like this:
If you’re generating an image dynamically based on post data and don’t want to save it to the server, sending it to be displayed can cause problems as when the person tries to save it, the browser will request it again from the server (causing any post data to be lost and probably a corrupted png).
The easiest way to get around this is to force it to download using the content disposition header, for example:
( ‘Content-Disposition: Attachment;filename=image.png’ );
header ( ‘Content-type: image/png’ );
?>
When you allow multiple output formats, (jpg/png) but want to use the 1-100 quality scale (like jpg), you will have to format the number:
I have experienced segfaults and bus errors with the following configuration: FreeBSD4.4, Apache 1.3.26, PHP 4.2.2, GD-1.8.4, PDFlib 4.0.1. The apache process crashed when calling the imagepng function, but it didn’t crash when calling the imagejpg function, or imagecreatefrompng.
Some wasted hours (lots) later, in which I have tried to recompile gd, libpng, php, libjpeg, what-not, I have found the following advices:
http://bugs.php.net/bug.php?id=16841
Hope this helps,
bogdan
barts code below does not work at least with gd 2
Only returns a blank image with alpha not the source resized
ps you also forgot image destroy and you had a random var in imagepng undefined in your post
If you are outputting a PNG directly in response to a client request it is important to check your web server configuration.
Some clients may request your images with a http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html»>accept header of image/*. Default configurations of Apache and possibly other servers will by default NOT allow your script to run in response to this request.
Apache is specifically discussed at http://stackoverflow.com/q/19169337 but other server have been documented to have issue too.
In other words, when testing your application don’t just use the web browser, consider a phone’s browser and networking libraries which could send different headers.
Creating a transparent image filled with tranparent color only
I had some hard times putting up this one:
apparently something changed from php 5.5 to 5.6.
I used to call ImagePng($image, »);
apparently this doesn’t work anymore in 5.6 as it returns: imagepng(): Filename cannot be empty
seems to work fine though.
$blob = ob_get_contents ();
ob_end_clean ();
// Results (some omitted for brevity):
// Size: 32x32px:
// quality: 0, size: 3172, elapsed: 0.00013399124145508
// quality: 1, size: 266, elapsed: 9.4890594482422E-5
// quality: 2, size: 264, elapsed: 7.7009201049805E-5
// quality: 3, size: 223, elapsed: 7.4863433837891E-5
// quality: 4, size: 225, elapsed: 8.5830688476562E-5
// quality: 5, size: 209, elapsed: 8.5115432739258E-5
// quality: 6, size: 208, elapsed: 9.608268737793E-5
// quality: 7, size: 205, elapsed: 0.0001060962677002
// quality: 8, size: 186, elapsed: 0.00015091896057129
// quality: 9, size: 181, elapsed: 0.00022006034851074
// Size: 128x128px:
// quality: 0, size: 49425, elapsed: 0.0010969638824463
// quality: 1, size: 976, elapsed: 0.00091886520385742
// quality: 2, size: 938, elapsed: 0.00088310241699219
// quality: 3, size: 925, elapsed: 0.00087594985961914
// quality: 4, size: 608, elapsed: 0.0009760856628418
// quality: 5, size: 607, elapsed: 0.00098395347595215
// quality: 6, size: 601, elapsed: 0.0010099411010742
// quality: 7, size: 602, elapsed: 0.001086950302124
// quality: 8, size: 521, elapsed: 0.001910924911499
// quality: 9, size: 491, elapsed: 0.0029060840606689
// Size: 512x512px:
// quality: 0, size: 788279, elapsed: 0.012928009033203
// quality: 1, size: 12467, elapsed: 0.013065099716187
// quality: 2, size: 11885, elapsed: 0.013008117675781
// quality: 3, size: 11190, elapsed: 0.013030052185059
// quality: 4, size: 7311, elapsed: 0.016619920730591
// quality: 5, size: 6994, elapsed: 0.016351222991943
// quality: 6, size: 6475, elapsed: 0.016234159469604
// quality: 7, size: 6432, elapsed: 0.016525983810425
// quality: 8, size: 6094, elapsed: 0.022937774658203
// quality: 9, size: 5649, elapsed: 0.065664052963257
// Size: 2048x2048px:
// quality: 0, size: 12605375, elapsed: 0.20983290672302
// quality: 1, size: 451735, elapsed: 0.19678711891174
// quality: 2, size: 409375, elapsed: 0.19415307044983
// quality: 3, size: 366404, elapsed: 0.20460414886475
// quality: 4, size: 312538, elapsed: 0.22785305976868
// quality: 5, size: 281671, elapsed: 0.23320484161377
// quality: 6, size: 244248, elapsed: 0.28935289382935
// quality: 7, size: 238310, elapsed: 0.33481192588806
// quality: 8, size: 217038, elapsed: 0.71698379516602
// quality: 9, size: 208881, elapsed: 1.858146905899
?>
My script was unable to complete: Fatal error: Allowed memory size of XX bytes exhausted (tried to allocate XX+n bytes).
I found out that PHP handles images in uncompressed format: my input image was 8768×4282@32 bit =>
150 MB per single in-memory copy.
As a solution, you can either check the dimensions and reject anything too big or, as I did, use ini_set(‘memory_limit’,’1024M’); on the page start (if your server has enough on board memory).
to all the ones, who like having their users fill their profil with an image without destroying a fixed design the following should be a great way to handle this problem.
but this file does more than this. it also adds black borders to files that are smaller than the max. size, so adding borders to the left and right where a image is too high 🙂
Well there are other features of the script, just try’em out and have fun with it 🙂
# minimal & maximum zoom
$minZoom = 1 ; # per cent related on orginal (!=0)
$maxZoom = 200 ; # per cent related on orginal (!=0)
PNG files are already compressed. They use a lossless compression algorithm. If you are using HighColour images, the compression only does so much. For low colour images (16 or 256) the compression is much better.
It is pointless trying to compress the images further before sending to a browser.
I ran across the following WRT sessions and image creation.
// aid of the highlighted Alliance
$marked_aid = 2403 ;
// Preferences
$mysqlhost = ‘localhost’ ;
$mysqluser = ‘user’ ;
$mysqlpass = ‘password’ ;
$mysqldb = ‘database’ ;
// These variables save the location on which we are currently drawing
$x_pointer = 0 ;
$y_pointer = 0 ;
// Increase pointer for X-coordinate
$x_pointer ++;
>
// Increase pointer for Y-coordinate
$y_pointer ++;
// We reached the end of a line and have to set the X-pointer to 0 again
$x_pointer = 0 ;
>
>
// Select the HTTP-Header for the selected filetype
header ( «Content-Type: image/png» );
Черный фон сзади у png
Нашел скрипт наложения картинки на картинку,но когда попадаются картинки в png с прозрачными участками,то они превращаются в черный.
Как отменить черный фон,я куча способов перепробовал
и ставил
imagealphablending
Помощь в написании контрольных, курсовых и дипломных работ здесь.
Как можно поставить фон сзади панели
В общем по дисциплине сказали сделать сайт (не рабочую просто шаблон) дали тему, в общем как можно.
Сделать прозрачный фон у png
Здравствуйте. Имею код: QPainter painter; painter.begin(&printer); QImage.
Помощь в написании контрольных, курсовых и дипломных работ здесь.
PNG фон серый, а не прозрачный
Новичок JavaFx, при помещении PNG изображения c прозрачным фоном в ImageView он отображается как.
Не удаляется прозрачный фон у png
html, body, div, h1, h2, h3, h4, h5, h6, ul, ol, dl, li, dt, dd, p, blockquote, pre, form.
Png как фон формы, перемещение
Столкнулся с такой проблемой, при перемещении формы с PNG картинкой взятой за фон, она при создании.
Не отображается прозрачный фон png рисунка в ие 6
Всем привет. Мне нужно вставить png(gif не катит) с прозрачным фоном в html, а у шефа как на зло.