PHP/Graphics Image/imagecreatefrompng — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 10:05, 26 мая 2010
Color and Image Fills
<source lang="html4strict">
<?php
$red = imagecolorallocate($image, 255, 0, 0); imagefill($image, 0, 0, $red); imagefilltoborder($image, 0, 0, $white, $red);
$_GET["size"] = 44; $_GET["text"] = "Hello, world!"; $size = imagettfbbox($_GET["size"], 0, "ARIAL", $_GET["text"]); $xsize = 50; $ysize = 60; $image = imagecreate($xsize, $ysize); $blue = imagecolorallocate($image, 0, 0, 255); $white = ImageColorAllocate($image, 255,255,255); imagettftext($image, $_GET["size"], 0, abs($size[0]), $ysize, $white, "ARIAL","asdfasdf"); $bg = imagecreatefrompng("button_mini.png"); imagesettile($image, $bg); imagefill($image, 0, 0, IMG_COLOR_TILED); header("content-type: image/png"); imagepng($image); imagedestroy($image); imagedestroy($bg);
?>
</source>
Create image object from PNG
<source lang="html4strict">
<?php
$stars = imagecreatefrompng("stars.png"); $gradient = imagecreatefrompng("gradient.png"); imagecopymerge($stars, $gradient, 0, 0, 0, 0, 256, 256, 60); header("Content-type: image/png"); imagepng($stars); imagedestroy($stars); imagedestroy($gradient);
?>
</source>
Loading Existing Images
<source lang="html4strict">
<?php
$_GET["size"] = 26; $_GET["text"] = "Button text"; $size = imagettfbbox($_GET["size"], 0, "ARIAL", $_GET["text"]); $xsize = abs($size[0]) + abs($size[2]); $ysize = abs($size[5]) + abs($size[1]); $image = imagecreatefrompng("button.png"); $imagesize = getimagesize("button.png"); $textleftpos = round(($imagesize[0] - $xsize) / 2); $texttoppos = round(($imagesize[1] + $ysize) / 2); $white = ImageColorAllocate($image, 255,255,255); imagettftext($image, $_GET["size"], 0, $textleftpos, $texttoppos, $white, "ARIAL", $_GET["text"]); header("content-type: image/png"); imagepng($image); imagedestroy($image);
?>
</source>