(c) Larry Ewing, Simon Budig, Garrett LeSage
� 1994 �.

������� ����������� � ��������������� �����������

������ | ����� | � ������� | ��������� ��������� | ����������� ��� | �������� ���/AMICT
���������� | ���������� | ������� ������� | ������-��������� | �������� � ��������� ������
�������������� ������� | ���������� | ����� �������� | ���������� ����������

���� ������

�������� ������ ������ �� ����������� ��������� php �� ������� ��������� ������� ��������� � �������� ����������� GD. ������� ������������ PHP http://php.net, ��������� ��������� ����� ������ �������, ���������� ���������, ���������, ������������ ��������.

�������� ������

�������� ��������� ���������� � public_html. � ������ ������� ��� ��������� ������ ��� ����������, ����� ������������� ��� � ����������� .php.

1. ������ ��������

������������ ������ ������� (piramida):
<?php
$im = imagecreatetruecolor(200, 200);

$blue = imagecolorallocate($im, 0, 0, 255);
$red = imagecolorallocate($im, 255, 0, 0);
$green = imagecolorallocate($im, 0, 255, 0);

imagefilledrectangle ($im, 20, 20, 60,60, $red); //������� �������������

imagefilledellipse($im, 50, 160, 30, 30, $green); //������� ����

// ������ ����� ��� ������������
$values = array(
            150,  110,  // Point 1 (x, y)
            140,  130, // Point 2 (x, y)
            160,  130,  // Point 3 (x, y)
            );

// ��������� ������������
imagefilledpolygon($im, $values, 3, $blue);

// ����������
header("Content-type: image/png");
imagepng($im);

// ������������ ������
imagedestroy($im);

?>
��������� � ������� php.net ������� �������, ������������ � �������. �������� ��������� ������� ����� �������, ����� ���������� ����������� ��������: ����� - ����� �������, �������� - ������� ����, ������ - ������� �����������.

2. �����������

������������ ������ ������� (demotivator):
<?php

// ��� ����������� - jpg
header('Content-Type: image/jpeg');

// �������� ����� � ��������� � ��������� ��� � ��������������� $im
$im = imagecreatefromjpeg("./1.jpg");

// �������� ����� ������
$text_color = imagecolorallocate($im, 255, 65, 91);

// ���������� ������ ������ ������� (��������!) 5 � ���������� 5, 5
imagestring($im, 5, 250, 350,  "HELLO WORLD", $text_color);

// ����� ����������� � �������
imagejpeg($im);

// ������������ ������
imagedestroy($im);
?>
���������� �������������� ��������� ������ ���������, ���������� ������ ������� � ������ ����������. ������ ������� "HELLO WORLD" ������� ������� ���������� (UTF8) "��� �� ���������". ��������: � �������� ���������� ������� ��� ������� imagestring() �� ������ ������������� ������. ��� ������� �������� ����������:
  1. ������� ������ ������� imagettftext(), ������ ���������� � ������ ������������� (��. php.net ����� �������� �������).
  2. ��������� ���� � �������� 1.jpg � ���� � TrueType ������� arial.ttf � ������� ����������.
  3. ������������ �� ������ 1 ������� ������ "��� �� ���������", ����� ��������� ���������: ������_������=36; ���������� (x, y)=(65, 380); ���� ������ - ����� (R,G,B=255,255,255).
  4. � ������� ������� imagejpeg() ��������� ����� ������������� ����������� � ���� demotivator.jpg

3. ����� ���

������������ ������ ������� (graycat):
<?php

$im = imagecreatefromjpeg("./cat.jpg");



// ������������� ��� �����������
header('content-type: image/jpeg');


// ����� ����������� �� �����
imagejpeg($im);

// ������� ������
imagedestroy($im);

?>
��������� ������������� �������� cat.jpg � �����-����� ������. ��� ����� ���������� ��������� � ����������� ������� imagefilter() � ��������������� �������� (����� �������������� ����� php.net). ������ ������ �������� �� ����� ��������������� ����������� � ���������� ��� � ���� graycat.jpg