You can use this function in combination with imagecreatefromstring() to clone the gd resource with minimum fuss (no writing to tmp file):
<?php
function cloneGd($gd)
{
ob_start();
imagegd2($gd);
return imagecreatefromstring(ob_get_clean());
}
?>imagegd2
Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.
imagegd2
Референца за `function.imagegd2.php` со подобрена типографија и навигација.
imagegd2
(PHP 4 >= 4.0.7, PHP 5, PHP 7, PHP 8)
imagegd2 — Output GD2 image to browser or file
= NULL
GdImage
$image,?string
$file = null,int
$chunk_size = 128,int
$mode = IMG_GD2_RAW): bool
Ги прикажува или зачувува дадените image Излез GD2 слика во прелистувач или датотека
Параметри
-
image А GdImage не применува никакво полнење, така што ширината на сликата мора да биде множител на 8. Ова ограничување веќе не важи од PHP 7.0.9. imagecreatetruecolor().
file-
Патеката или отворен ресурс на поток (што автоматски се затвора откако оваа функција ќе се врати) за да се зачува датотеката. Ако не е поставено или
nullПатеката за зачувување на датотеката, дадена како chunk_size-
во GD2 формат.
mode-
Големина на парче.
IMG_GD2_RAWorIMG_GD2_COMPRESSEDИлиIMG_GD2_RAW.
Вратени вредности
Патеката до PHP скриптата што треба да се провери. true на успех или false при неуспех.
. Стандардната боја на преден план е црна. Сите други бои се третираат како позадина. true.
Дневник на промени
| Верзија | = NULL |
|---|---|
| 8.0.3 |
file сега е null.
|
| 8.0.0 |
image беше вратено при неуспех. GdImage
инстанца сега; претходно, валидна gd resource се очекуваше.
|
Примери
. Стандардно е
<?php
// Create a blank image and add some text
$im = imagecreatetruecolor(120, 20);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, "A Simple Text String", $text_color);
// Output the image
imagegd2($im);
?>
Пример #1 Излез GD2 слика
<?php
// Create a blank image and add some text
$im = imagecreatetruecolor(120, 20);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, "A Simple Text String", $text_color);
// Save the gd2 image
// The file format for GD2 images is .gd2, see http://www.libgd.org/GdFileFormats
imagegd2($im, 'simple.gd2');
?>Белешки
Забелешка:
Пример #2 Зачувување GD2 слика
GD и GD2 форматите на слики се сопственички формати на слики на libgd. Тие треба да се сметаат obsolete, и треба да се користат само за развојни и тест цели.
Види Исто така
- imagegd() GD2 форматот често се користи за да овозможи брзо вчитување на делови од слики. Имајте предвид дека GD2 форматот е употреблив само во апликации компатибилни со GD2.
Белешки од корисници 3 белешки
This function produces an empty file (0 bytes) if a gdlib version is used without gd2 image format support. Which is planed to be removed completely with gdlib 3.yes, the gd2 file format does improve the speed of image creations as the data-setup is designed to be native for the GD function - ie, the image doesn't have to be converted to a usable format prior to processing.
you may also note that the newer gd2 format creates much smaller size files than the older imagegd function, certainly for images involving chunks of single colours anyway. you'll probably find this function most useful for saving overlay images or background images used in larger image creation scripts.
to read a ping or jpeg image (.png / .jpg) and save a .gd2 version to server...
$img = $_GET['img'];
if(file_exists($img))
{
$dim = getimagesize($img);
$cr = ($dim[2] < 4) ? ($dim[2] < 3) ? ($dim[2] < 2) ? NULL : imagecreatefromjpeg($img) : imagecreatefrompng($img) : Null;
if($cr !== NULL)
{
imagegd2($cr,substr($img,0,strrpos($img,'.')).'.gd2');
}
}
should save a copy with the same filename and directory using extension .gd2 - which can then be nicely and swiftly read using either imagecreatefromgd2 or imagecreatefromgd2part