Документ взят из кэша поисковой машины. Адрес оригинального документа : http://star.arm.ac.uk/archives/Clocks/BettsImages/_source/PHP_%20imagecopyresized%20-%20Manual.mht
Дата изменения: Wed Jun 27 17:40:05 2012
Дата индексирования: Sun Apr 10 11:56:09 2016
Кодировка:

Поисковые слова: m 8
Content-Type: multipart/related; start=; boundary=----------6nhAxGuvOMzG6waYgcmWNI
Content-Location: http://php.net/manual/en/function.imagecopyresized.php
Subject: =?utf-8?Q?PHP:=20imagecopyresized=20-=20Manual?=
MIME-Version: 1.0

------------6nhAxGuvOMzG6waYgcmWNI
Content-Disposition: inline; filename=function.imagecopyresized.htm
Content-Type: text/html; charset=utf-8; name=function.imagecopyresized.htm
Content-ID:
Content-Location: http://php.net/manual/en/function.imagecopyresized.php
Content-Transfer-Encoding: Quoted-Printable

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd=
">
>

PHP: imagecopyresized - Manual




"/>
avicon.ico" />





" />
k" href=3D"http://php.net/imagecopyresized" />
0/" about=3D"#content" />
copyresized.php" />

p" />














search for

y=3D"s" />
in the

src=3D"http://static.php.net/www.php.net/images/small_submit_w=
hite.gif"
class=3D"submit" alt=3D"search" />















imagecreate tic.php.net/www.php.net/images/caret-r.gif" alt=3D">" width=3D"11" he=
ight=3D"7" />



php.net/www.php.net/images/caret-l.gif" alt=3D"<" width=3D"11" height=
=3D"7" />imagecopyresampled




[ PHP&perm=3Den/function.imagecopyresized.php">edit] Last updated:=
Fri, 22 Jun 2012



view this page in


/small_submit.gif" id=3D"changeLangImage" alt=3D"Change language" />







imagecopyresized


(PHP 4, PHP 5)

lass=3D"refname">imagecopyresized ">Copy and resize part of an image




sized-description">

Description



bool i=
magecopyresized

( resource <=
code class=3D"parameter">$dst_image

, resource ode class=3D"parameter">$src_image
, int lass=3D"parameter">$dst_x
, int lass=3D"parameter">$dst_y
, int lass=3D"parameter">$src_x
, int lass=3D"parameter">$src_y
, int lass=3D"parameter">$dst_w
, int lass=3D"parameter">$dst_h
, int lass=3D"parameter">$src_w
, int lass=3D"parameter">$src_h
)



imagecopyresized() =
copies a rectangular
portion of one image to another image.
dst_image is the destinatio=
n image,
src_image is the source ima=
ge identifier.



In other words, imagecopyresized()<=
/strong>
will take an =

rectangular area from src_image<=
/em> of width =

src_w and height class=3D"parameter">src_h at =

position (src_x, lass=3D"parameter">src_y) =

and place it in a rectangular area of d=
st_image
=

of width dst_w and height <=
em>dst_h

at position (dst_x, e class=3D"parameter">dst_y).



If the source and destination coordinates and width and heights
differ, appropriate stretching or shrinking of the image fragment
will be performed. The coordinates refer to the upper left
corner. This function can be used to copy regions within the
same image (if dst_image is=
the same as
src_image) but if the regio=
ns overlap the
results will be unpredictable.




ized-parameters">

Parameters







dst_image=



Destination image link resource.








src_image=



Source image link resource.








dst_x >



x-coordinate of destination point.








dst_y >



y-coordinate of destination point.








src_x >



x-coordinate of source point.








src_y >



y-coordinate of source point.








dst_w >



Destination width.








dst_h >



Destination height.








src_w >


Source width.








src_h >


Source height.











esized-returnvalues">

Return Values



Returns TRUE on success or e>FALSE on failure.




ed-examples">

Examples




Example #1 Resizing an image



This example will display the image at half size.




<?php
: #FF8000">// File and new size
yle=3D"color: #0000BB">$filename  00">=3D 'test.jpg' n style=3D"color: #007700">;
=
$percent 
=3D  n style=3D"color: #0000BB">0.5; />
// Content type=

header color: #007700">('Content-Type:&nb=
sp;image/jpeg'
);

>// Get new sizes
pan>list( 00BB">$width yle=3D"color: #0000BB">$height)&nb=
sp;=3D 
getimagesize an style=3D"color: #007700">(
$file=
name
);
color: #0000BB">$newwidth =3D=
 
$width  le=3D"color: #007700">* $perc=
ent
;
lor: #0000BB">$newheight =3D&=
nbsp;
$height  le=3D"color: #007700">* $perc=
ent
;

=3D"color: #FF8000">// Load
BB">$thumb =3D  pan style=3D"color: #0000BB">imagecreatetruecolor
olor: #007700">($newwidth pan style=3D"color: #007700">,  ">$newheight);
tyle=3D"color: #0000BB">$source  0">=3D imagecreatefromjpeg
pan>( ">$filename);

pan style=3D"color: #FF8000">// Resize
olor: #0000BB">imagecopyresized( span>$thumb 007700">, $source style=3D"color: #007700">, 0=
: #0000BB">0 yle=3D"color: #0000BB">0
pan>0 ">, $newwidth le=3D"color: #007700">, $newh=
eight
color: #0000BB">$width
n>$height 7700">);

// Output=

imagejpeg "color: #007700">($thumb an style=3D"color: #007700">);
">?>




The above example will output
something similar to:



=


ed.jpg" alt=3D"Output of example : Resizing an image" width=3D"47" heigh=
t=3D"25" />



The image will be output at half size, though better
quality could be obtained using "function.imagecopyresampled.php" class=3D"function">imagecopyresampled(=
)
.






notes">

Notes


Note: =


There is a problem due to palette image limitations (255+1 colors).
Resampling or filtering an image commonly needs more colors than 255=
, a
kind of approximation is used to calculate the new resampled pixel a=
nd its
color. With a palette image we try to allocate a new color, if that=

failed, we choose the closest (in theory) computed color. This is
not always the closest visual color. That may produce a weird result=
, like
blank (or visually blank) images. To skip this probl