����������
WEB - ������

www.spravkaweb.ru Rambler's Top100
 ï¿½ï¿½ ����������: �������/PHP/������ � ������������� � ���������� GD.��������������� �������������Ðàñïå÷àòàòü 
�������
�������
����� ���
HTML
JavaScript
VBScript
CSS
Flash
Perl
PHP
MySQL
SSI
VRML
�������������
������
Download
�����
��������
������
�������� ���
�����:
��������
Subscribe.Ru:

PHP

<--����� | ��������� � ������ | ������-->
������ � ������������� � ���������� GD
��������������� �������������
imageCreate
�������� ������ ��������.

��������� :
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);
?>

imageCreateFromPng
�������� ������� �� ����� 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;
}

imageCreateFromJpeg
�������� ������� �� ����� JPEG.

��������� :
int imageCreateFromJpeg(string filename)
��� ������� ��������� ����������� �� ����� � ������ � ���������� ��� �������������. ��� � ����� ������ imageCreate(), ���������� ������ � ��������� �������� ������ ����� ���� �������������. ��� �������� � ����� ����������� ��������������� � ��������� � ������ ��� � ������������� �������, ��� ���� ����� ����� ���� ����������� ������ ����������� � ��� ��������� ��������, ����� ��� ���������������, ��������� ����� � �.�.


imageCreateFromGif
�������� ������� �� ����� GIF.

��������� :
int imageCreateFromGif(string filename)
��� ������� ��������� ����������� �� ����� � ������ � ���������� ��� �������������. ��� � ����� ������ imageCreate(), ���������� ������ � ��������� �������� ������ ����� ���� �������������. ��� �������� � ����� ����������� ��������������� � ��������� � ������ ��� � ������������� �������, ��� ���� ����� ����� ���� ����������� ������ ����������� � ��� ��������� ��������, ����� ��� ���������������, ��������� ����� � �.�.

����� ���������, ��� GD ������� � ������ 1.6 �� ������������ ������ GIF. � ����� � ���� ������ ������� ����������� �� ������������.


imagePng
������� ������� ����������� � 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);
?>

imageJpeg
������� ������� 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);
?>

image2WBMP
����� ����������� � ������� ��� ����.

��������� :
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 ��� ����.

imageGif
������� ������� GIF �������� ��� ���������� ��� � �����.

���������:
int imageGIF(int im [, string filename])

������� ��������� �����������, �������� ����� ��������������� � ����������� � ������, �� ����, ��� �� ������� ��� � �������.

����������, ������� ����������� ������ ���� ��������� ��� ������� ��� ������ ������� imageCreate(), �.�. �� ������ ����� ��� ������������� im.

���� �������� filename ������, �� ������ ������ � ��������������� ������� ��������� ����� � ����������� �������� �����, �.�. � �������. ������ ��������� Content-type ��� ���� �� ���������, ����� ���� ����� �������� ��� ������� ��� ������ Header().
����������, �� ������ ������� ���� �� ���� ������, � ����������� �� ���� �����������:

Header("Content-type: image/gif").

�.�. ���������� GD, ������� � ������ 1.6, �� ������������ ������ GIF, ������ ������� ������������ �����.


imageCopy
����������� ����� �������.

��������� :
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");
?>

imageCopyResized
����������� ����� ������� � ����������������.

��������� :
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);
?>

imageDestroy
����������� �������.

��������� :
int imageDestroy(int im)

������� ���������� ���������� im ����� ���������� ������� (��������� �������� ����� fclose() ����� �������� fopen()).

�� ���������� ����� ����� ������� "PHP 4. ����������� ����������."
www.piter.com
������ / � ����������
 
Download
Ñêà÷àòü ñïðàâî÷íèê ïî PHP
��� ������:
05.07.2004
  • � ������� PHP ��������� ��������� ������� ��� ������ � ���������� (���������� GD):
    imagetypes(), ...
  • � ������� JavaScript ��������� �������� �� ����� D, E, F, H, I
  • � ������� ������ ��������� ������, �������������� ��� �������� � html-�������� ��������� MS Office (Word, Excel � �.�.)
  • �����������:
    ��� ��� ������ ����� �� �������� � �����������:
    ��� ��������.
    ������ �� ��������.
    ���� ��������.
    �������� �������� �������.
    �� ��� ������� �������.
    � ����������� ���� ������.
    � ��� ��� �����.
    ������.
    ��������:
    Rambler's Top100
    Ñäåëàòü ñòðàíèöó ñòàðòîâîé ������� �������� ���������
    Äîáàâèòü ñòðàíèöó â èçáðàííîå �������� ���� � ���������
    Ñîîáùèòü îá íàéäåííîé îøèáêå �������� �� ������