imagecopyresized 


gd apg

COPY and RESIZE an entire or part image..





This function copies a rectangular portion of one image to another image, smoothly interpolating pixel values so that, in particular, reducing the size of an image still retains a great deal of clarity.

This function will take a rectangular area from $src_image of width $src_width and height $src_height at position ($src_x, $src_y) and place it in a rectangular area of $dst_image of width $dst_width and height $dst_height at position ($dst_x, $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 regions overlap the results will be unpredictable.

The results may be less interesting than those obtained through imagecopyresampled.

This function returns TRUE on success or FALSE on failure.



<?php

bool imagecopyresized 
GdImage $dst_imageage,
                                       
GdImage $src_imageage
                                                
int $dst_xint $dst_y
                                                
int $src_xint $src_y
                                                
int $dst_widthint $dst_height
                                                
int $src_widthint $src_height )


where,

$dst_image The destination image identifier

$src_image 
The source image identifier

$dst_x 
The x-coordinate of destination point 

$dst_y 
The y-coordinate of destination point 

$src_x 
The x-coordinate of source point 

$src_y 
The y-coordinate of source point 

$dst_width 
The destination width 

$dst_height 
The destination height

$src_width 
The source width 

$src_height 
The source height

?>
 

  $dst_image   


The destination image identifier.



  $src_image   


The source image identifier.



  $dst_x   


The x-coordinate of destination point.



  $dst_y   


The y-coordinate of destination point.



  $src_x   


The x-coordinate of source point.



  $src_y   


The y-coordinate of source point.



  $dst_width   


The destination width.



  $dst_height   


The destination height.



  $src_width   


The source width.



  $src_height   


The source height.



  1 EXERCISE   

<?php

echo 'PHP VERSION: ' PHP_VERSION '<br><br>';

// $lang = 'pt';
$lang 'en';

$base_img01 "jpeg/JPEG 024 01.jpg";
// Toledo - Spain

$dest_img01 "png/PNG 043 01-(.3x).png";

$id_base01 imagecreatefromjpeg($base_img01);
$base_w01 imagesx($id_base01);
$base_h01 imagesy($id_base01);
$dim01 '( ' $base_w01 'px X ' $base_h01 'px )';

echo 
$base_img01?><br><br>
 <?php echo $dim01?><br><br>
<img src="<?php echo $base_img01?>"
 alt="<?php echo $base_img01?>
 title="<?php echo $base_img01?>" width="400">
 <br><br><br>

<?php

// 30% of the original image
$dest_w01 bcmul($base_w010.3); 
$dest_h01 bcmul($base_h010.3); 

$id_dest01 imagecreatetruecolor($dest_w01$dest_h01);

$dest_x01 0

$dest_y01 0

$src_x01 0

$src_y01 0

$bool_res01 imagecopyresized($id_dest01$id_base01
                                                   
$dest_x01$dest_y01
                                                   
$src_x01$src_y01
                                                   
$dest_w01$dest_h01
                                                   
$base_w01$base_h01);

if(
$bool_res01 == FALSE)
{
$pt "A imagem não pôde ser redimensionada!";
$en "The image could not be resized!";
echo 
'<br><br>' . $$lang '<br><br>';
}
else
{
imagepng($id_dest01$dest_img01);

$dest_w01 imagesx($id_dest01);
$dest_h01 imagesy($id_dest01);
$dim01 '( ' $dest_w01 'px X ' $dest_h01 'px )';

echo 
$dest_img01?><br><br>
 <?php echo $dim01?><br><br>
<img src="<?php echo $dest_img01?>"
 alt="<?php echo $dest_img01?>
 title="<?php echo $dest_img01?>" width="200">
<?php
}
?>

 RESULT   

JPEG 024 01.jpg

( 2384px X 2411px )

JPEG 024 01.jpg apr


PNG 043 01-(.3x).png

( 715px X 723px )

PNG 043 01-(.3x).png apr

  2 EXERCISE   

<?php

echo 'PHP VERSION: ' PHP_VERSION '<br><br>';

// $lang = 'pt';
$lang 'en';

$base_img02 "bmp/BMP 009 03 Katedrála Sv. Víta.bmp";

$dest_img02 "bmp/BMP 009 02 Katedrála Sv. Víta.(1.5x).bmp";
 
$id_base02 imagecreatefrombmp$base_img02);
$base_w02 imagesx($id_base02);
$base_h02 imagesy($id_base02);
$dim02 '( ' $base_w02 'px X ' $base_h02 'px )';

echo 
$base_img02?><br><br>
 <?php echo $dim02?><br><br>
<img src="<?php echo  $base_img02?>"
 alt="<?php echo $base_img02?>
 title="<?php echo $base_img02?>" width="200">
 <br><br><br>

<?php

$dest_w02 
bcmul($base_w021.5); // 50% higher 
$dest_h02 bcmul($base_h021.5); // 50% higher 

$id_dest02 imagecreatetruecolor($dest_w02$dest_h02);

$dest_x02 0;  

$dest_y02 0;  

$src_x02 0;  

$src_y02 0

$b_res02 imagecopyresized($id_dest02$id_base02
                                              
$dest_x02$dest_y02
                                              
$src_x02$src_y02
                                              
$dest_w02$dest_h02
                                              
$base_w02$base_h02);

if(
$b_res02 == FALSE)
{
$pt "A imagem não pôde ser redimensionada!";
$en "The image could not be resized!";
echo 
'<br><br>' . $$lang '<br><br>';
}
else
{
imagepng($id_dest02,  $dest_img02);

$dest_w02 imagesx($id_dest02);
$dest_h02 imagesy($id_dest02);
$dim02 '( ' $dest_w02 'px X ' $dest_h02 'px )';

echo 
$dest_img02?><br><br>
 <?php echo $dim02?><br><br>
<img src="<?php echo  $dest_img02?>"
 alt="<?php echo $dest_img02?>
 title="<?php echo $dest_img02?>" width="450">
<?php

}
?>

 RESULT   

BMP 009 03 Katedrála Sv. Víta.bmp

( 616px X 408px )

BMP 009 03 Katedrála Sv. Víta.bmp apr


BMP 009 02 Katedrála Sv. Víta.(1.5x).bmp

( 924px X 612px )

BMP 009 02 Katedrála Sv. Víta.(1.5x).bmp apr