�������� ������ ��������.
��������� :
int imageCreate(int x, int y)
������� ������ �������� �������� x �� y ����� � ���������� �� �������������. ����� ����, ��� �������� �������, ��� ������ � ��� �������������� ������ ����� ���� �������������, �� �������� � ���, ��� �� �������� � ������ ����� ��� ����������.
������:
�������� ����� �������� ��� ������ GD � ����� �� � ����� ��������:
<?php header ("Content-type: image/png"); $im = @imagecreate (50, 100) or die ("�� ������� ������� ����� ��������!"); $background_color = imagecolorallocate ($im, 255, 255, 255); $text_color = imagecolorallocate ($im, 233, 14, 91); imagestring ($im, 1, 5, 5, "A Simple Text String", $text_color); imagepng ($im); ?>
�������� ������� �� ����� PNG.
��������� :
int imageCreateFromPng(string filename)
��� ������� ��������� ����������� �� ����� PNG � ������ � ���������� ��� �������������. ��� � �����
������ imageCreate(), ���������� ������ � ��������� ��������
������ ����� ���� �������������. ��� �������� � ����� ����������� ��������������� � ��������� �
������ ��� � ������������� �������, ��� ���� ����� ����� ���� ����������� ������ ����������� �
��� ��������� ��������, ����� ��� ���������������, ��������� ����� � �.�.
������:
������ ���������� ������ ��� �������� ������������ �����.
function LoadPNG ($imgname) { $im = @imagecreatefrompng ($imgname); /* Attempt to open */ if (!$im) { /* See if it failed */ $im = imagecreate (150, 30); /* Create a blank image */ $bgc = imagecolorallocate ($im, 255, 255, 255); $tc = imagecolorallocate ($im, 0, 0, 0); imagefilledrectangle ($im, 0, 0, 150, 30, $bgc); /* Output an errmsg */ imagestring ($im, 1, 5, 5, "Error loading $imgname", $tc); } return $im; }
�������� ������� �� ����� JPEG.
��������� :
int imageCreateFromJpeg(string filename)
��� ������� ��������� ����������� �� ����� � ������ � ���������� ��� �������������. ��� � �����
������ imageCreate(), ���������� ������ � ��������� ��������
������ ����� ���� �������������. ��� �������� � ����� ����������� ��������������� � ��������� �
������ ��� � ������������� �������, ��� ���� ����� ����� ���� ����������� ������ ����������� �
��� ��������� ��������, ����� ��� ���������������, ��������� ����� � �.�.
�������� ������� �� ����� GIF.
��������� :
int imageCreateFromGif(string filename)
��� ������� ��������� ����������� �� ����� � ������ � ���������� ��� �������������. ��� � �����
������ imageCreate(), ���������� ������ � ��������� ��������
������ ����� ���� �������������. ��� �������� � ����� ����������� ��������������� � ��������� �
������ ��� � ������������� �������, ��� ���� ����� ����� ���� ����������� ������ ����������� �
��� ��������� ��������, ����� ��� ���������������, ��������� ����� � �.�.
����� ���������, ��� GD ������� � ������ 1.6 �� ������������ ������ GIF. � ����� � ���� ������ ������� ����������� �� ������������.
������� ������� ����������� � PNG-������� � ����� ������� ��� � ����.
���������:
int imagePng(int im [, string filename])
��� ������� ��������� �����������, �������� ����� ��������������� � ����������� � ������, �� ����, ��� �� ������� ��� � �������.
����������, ������� ����������� ������ ���� ��������� ��� ������� ��� ������ ������� imageCreate(), �.�. �� ������ ����� ��� ������������� im.
���� �������� filename ������, �� ������ ������ � ��������������� ������� ��������� �����
� ����������� �������� �����, �.�. � �������. ������ ��������� Content-type ��� ���� ��
���������, ����� ���� ����� �������� ��� ������� ��� ������ Header().
����������, �� ������ ������� ���� �� ���� ������, � ����������� �� ���� �����������:
Header("Content-type: image/png") ��� PNG.
������:
������ ������������� ������� imagepng():
<?php $im = imagecreatefrompng ("test.png"); Header("Content-type: image/png") imagepng ($im); ?>
������� ������� JPEG �������� ��� ���������� ��� � �����.
���������:
int imageJPEG(int im [, string filename [, int quality]])
��� ������� ��������� �����������, �������� ����� ��������������� � ����������� � ������, �� ����, ��� �� ������� ��� � �������.
����������, ������� ����������� ������ ���� ��������� ��� ������� ��� ������ ������� imageCreate(), �.�. �� ������ ����� ��� ������������� im.
���� �������� filename ������, �� ������ ������ � ��������������� ������� ��������� �����
� ����������� �������� �����, �.�. � �������. ������ ��������� Content-type ��� ���� ��
���������, ����� ���� ����� �������� ��� ������� ��� ������ Header().
����������, �� ������ ������� ���� �� ���� ������, � ����������� �� ���� �����������:
Header("Content-type: image/jpeg") ��� Jpeg
������ �������������� �������� quality ������ �������� ����������� (�� 0 �� 100).
<?php $im=imageCreateFromJPEG("img/file.jpg"); Header("Content-type: image/jpeg"); imageJPEG($im,"",30); ?>
����� ����������� � ������� ��� ����.
��������� :
int image2WBMP( resource image [, string filename [, int threshold]])
������� ������� �����������, �������� ������������ image, � �������, ���� � ����, ��� �������� ������ �������������� ���������� filename.
���� ����������� ��������� � �������, ���������� ������ ��� ��� WBMP ��� image/vnd.wap.wbmp �������� Header():
<?php $file = "php.png"; $image = imagecreatefrompng($file); header("Content-type: " . image_type_to_mime_type(IMAGETYPE_WBMP)); image2wbmp($image); // ����� wbmp-�������� � ������� ?>������� image2WBMP() �������� PHP ������ ���� ������ ���������� GD 1.8 ��� ����.
������� ������� GIF �������� ��� ���������� ��� � �����.
���������:
int imageGIF(int im [, string filename])
������� ��������� �����������, �������� ����� ��������������� � ����������� � ������, �� ����, ��� �� ������� ��� � �������.
����������, ������� ����������� ������ ���� ��������� ��� ������� ��� ������ ������� imageCreate(), �.�. �� ������ ����� ��� ������������� im.
���� �������� filename ������, �� ������ ������ � ��������������� ������� ��������� �����
� ����������� �������� �����, �.�. � �������. ������ ��������� Content-type ��� ���� ��
���������, ����� ���� ����� �������� ��� ������� ��� ������ Header().
����������, �� ������ ������� ���� �� ���� ������, � ����������� �� ���� �����������:
Header("Content-type: image/gif").
�.�. ���������� GD, ������� � ������ 1.6, �� ������������ ������ GIF, ������ ������� ������������ �����.
����������� ����� �������.
��������� :
int imageCopy(int dst_im, int src_im, int dst_x, int dst_y, int src_x, int src_y, int src_w, int src_h)
������� �������� ������������� ������� ������� � ������� (src_x, src_y) ������� src_w � ������� src_h �� ������� src_im � ������� dst_im, ������ ���������� ������� �������� (dst_x, dst_y).
� ��������� ������� ����� �������� file1.png ������� ����������� � file2.png
<?php // ������� ������ �������� �� ������ �������� ����������� $im1=imageCreateFromPNG("img/file1.png"); // ���������� �� ������� $size_x=imageSX($im1); $size_y=imageSY($im1); // ������� ������ ������ �������� $im2=imageCreate($size_x,$size_y); // �������� ������� ������� �� ������� ����������� �� ������ imageCopy($im2,$im1,0,0,0,0,$size_x,$size_y); // ���������� ������������� �������� � ����� imagePNG($im2, "img/file2.png"); ?>
����������� ����� ������� � ����������������.
��������� :
int imageCopyResized(int dst_im, int src_im, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH)
��� ������� - ���� �� ����� ������ � �������������. � ������� ��� ����� ���������� ����������� (��� �� �������), ���������� ��� �������������� ��.
dst_im ������ ������������� �����������, � ������� ����� ������� ��������� ������ �������. ��� ����������� ������ ��� ���� ������� ��� ��������� � ����� ���������� �������.
src_im - ������������� �����������, ��� ������� ���������� ������. �������, src_im � dst_im����� � ���������.
��������� srcX, srcY, srcW, srcH ������ ������� ������ ��������� �����������, ��� ������� ����� ������������ �������� - ��������������, ���������� �� �������� ������ ����, ������ � ������.
�������, �������� dstX, dstY, dstW, dstH ������ �� ����� �� ����������� dst_im, � ������� ����� "�������" ��������� � ���������� �������� �������������. ��������, ���, ���� ������ ��� ������ ���� ��������������� �� ���������, �� �������� ������������� ����� ������ ������� ��������� ��� �����.
� ��������� ������� ���� file1.jpg ����������� ����� � ������������ � ���� file2.jpg:
<?php $old = imageCreateFromJpeg("img/file1.jpg"); $w = imageSX($old); $h = imageSY($old); $w_new=rounr($w/2); $h_new=round($h/2); $new = imageCreate($w_new, $h_new); imageCopyResized($new, $old, 0, 0, 0, 0, $w_new, $h_new, $w, $h); imageJpeg($new, "img/file2.jpg"); imageDestroy($old); imageDestroy($new); ?>
����������� �������.
��������� :
int imageDestroy(int im)
������� ���������� ���������� im ����� ���������� ������� (��������� �������� ����� fclose() ����� �������� fopen()).