<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >imagecopyresized</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REL="HOME" TITLE="Manual do PHP" HREF="index.html"><LINK REL="UP" TITLE="Imagens, Funções de" HREF="ref.image.html"><LINK REL="PREVIOUS" TITLE="imagecopyresampled" HREF="function.imagecopyresampled.html"><LINK REL="NEXT" TITLE="imagecreate" HREF="function.imagecreate.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >Manual do PHP</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.imagecopyresampled.html" ACCESSKEY="P" >Anterior</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.imagecreate.html" ACCESSKEY="N" >Próxima</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.imagecopyresized" ></A >imagecopyresized</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN83818" ></A ><P > (PHP 3, PHP 4, PHP 5)</P >imagecopyresized -- Copy and resize part of an image</DIV ><DIV CLASS="refsect1" ><A NAME="AEN83821" ></A ><H2 >Descrição</H2 >bool <B CLASS="methodname" >imagecopyresized</B > ( resource dst_image, resource src_image, int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h )<BR ></BR ><P > <B CLASS="function" >imagecopyresized()</B > copies a rectangular portion of one image to another image. <CODE CLASS="parameter" >dst_image</CODE > is the destination image, <CODE CLASS="parameter" >src_image</CODE > is the source image identifier. 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 <CODE CLASS="parameter" >dst_image</CODE > is the same as <CODE CLASS="parameter" >src_image</CODE >) but if the regions overlap the results will be unpredictable. </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN83862" ></A ><H2 >Parâmetros</H2 ><P > <P ></P ><DIV CLASS="variablelist" ><DL ><DT ><CODE CLASS="parameter" >dst_im</CODE ></DT ><DD ><P > Destination image link resource </P ></DD ><DT ><CODE CLASS="parameter" >src_im</CODE ></DT ><DD ><P > Source image link resource </P ></DD ><DT ><CODE CLASS="parameter" >dst_x</CODE ></DT ><DD ><P > x-coordinate of destination point </P ></DD ><DT ><CODE CLASS="parameter" >dst_y</CODE ></DT ><DD ><P > y-coordinate of destination point </P ></DD ><DT ><CODE CLASS="parameter" >src_x</CODE ></DT ><DD ><P > x-coordinate of source point </P ></DD ><DT ><CODE CLASS="parameter" >src_y</CODE ></DT ><DD ><P > y-coordinate of source point </P ></DD ><DT ><CODE CLASS="parameter" >dst_w</CODE ></DT ><DD ><P > Destination width </P ></DD ><DT ><CODE CLASS="parameter" >dst_h</CODE ></DT ><DD ><P > Destination height </P ></DD ><DT ><CODE CLASS="parameter" >src_w</CODE ></DT ><DD ><P > Source width </P ></DD ><DT ><CODE CLASS="parameter" >src_h</CODE ></DT ><DD ><P > Source height </P ></DD ></DL ></DIV > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN83916" ></A ><H2 >Valores de retornado</H2 ><P > Retorna <TT CLASS="constant" ><B >TRUE</B ></TT > em caso de sucesso ou <TT CLASS="constant" ><B >FALSE</B ></TT > em falhas. </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN83921" ></A ><H2 >Exemplos</H2 ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN83924" ></A ><P ><B >Exemplo 1. Resizing an image</B ></P ><P > This example will display the image at half size. </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /></font><font color="#FF8000">// File and new size<br /></font><font color="#0000BB">$filename </font><font color="#007700">= </font><font color="#DD0000">'test.jpg'</font><font color="#007700">;<br /></font><font color="#0000BB">$percent </font><font color="#007700">= </font><font color="#0000BB">0.5</font><font color="#007700">;<br /><br /></font><font color="#FF8000">// Content type<br /></font><font color="#0000BB">header</font><font color="#007700">(</font><font color="#DD0000">'Content-type: image/jpeg'</font><font color="#007700">);<br /><br /></font><font color="#FF8000">// Get new sizes<br /></font><font color="#007700">list(</font><font color="#0000BB">$width</font><font color="#007700">, </font><font color="#0000BB">$height</font><font color="#007700">) = </font><font color="#0000BB">getimagesize</font><font color="#007700">(</font><font color="#0000BB">$filename</font><font color="#007700">);<br /></font><font color="#0000BB">$newwidth </font><font color="#007700">= </font><font color="#0000BB">$width </font><font color="#007700">* </font><font color="#0000BB">$percent</font><font color="#007700">;<br /></font><font color="#0000BB">$newheight </font><font color="#007700">= </font><font color="#0000BB">$height </font><font color="#007700">* </font><font color="#0000BB">$percent</font><font color="#007700">;<br /><br /></font><font color="#FF8000">// Load<br /></font><font color="#0000BB">$thumb </font><font color="#007700">= </font><font color="#0000BB">imagecreatetruecolor</font><font color="#007700">(</font><font color="#0000BB">$newwidth</font><font color="#007700">, </font><font color="#0000BB">$newheight</font><font color="#007700">);<br /></font><font color="#0000BB">$source </font><font color="#007700">= </font><font color="#0000BB">imagecreatefromjpeg</font><font color="#007700">(</font><font color="#0000BB">$filename</font><font color="#007700">);<br /><br /></font><font color="#FF8000">// Resize<br /></font><font color="#0000BB">imagecopyresized</font><font color="#007700">(</font><font color="#0000BB">$thumb</font><font color="#007700">, </font><font color="#0000BB">$source</font><font color="#007700">, </font><font color="#0000BB">0</font><font color="#007700">, </font><font color="#0000BB">0</font><font color="#007700">, </font><font color="#0000BB">0</font><font color="#007700">, </font><font color="#0000BB">0</font><font color="#007700">, </font><font color="#0000BB">$newwidth</font><font color="#007700">, </font><font color="#0000BB">$newheight</font><font color="#007700">, </font><font color="#0000BB">$width</font><font color="#007700">, </font><font color="#0000BB">$height</font><font color="#007700">);<br /><br /></font><font color="#FF8000">// Output<br /></font><font color="#0000BB">imagejpeg</font><font color="#007700">(</font><font color="#0000BB">$thumb</font><font color="#007700">);<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ><P >O exemplo acima irá imprimir algo similar a:</P ><P ><IMG SRC="figures/image.imagecopyresized.jpg"></P ><P > The image will be output at half size, though better quality could be obtained using <A HREF="function.imagecopyresampled.html" ><B CLASS="function" >imagecopyresampled()</B ></A >. </P ></DIV ></TD ></TR ></TABLE > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN83933" ></A ><H2 >Notas</H2 ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Nota: </B > 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 and 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 problem, please use a truecolor image as a destination image, such as one created by <A HREF="function.imagecreatetruecolor.html" ><B CLASS="function" >imagecreatetruecolor()</B ></A >. </P ></BLOCKQUOTE ></DIV ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN83938" ></A ><H2 >Veja também</H2 ><P > <A HREF="function.imagecopyresampled.html" ><B CLASS="function" >imagecopyresampled()</B ></A > </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.imagecopyresampled.html" ACCESSKEY="P" >Anterior</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Principal</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.imagecreate.html" ACCESSKEY="N" >Próxima</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >imagecopyresampled</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.image.html" ACCESSKEY="U" >Acima</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >imagecreate</TD ></TR ></TABLE ></DIV ></BODY ></HTML >