1--TEST-- 2imagecopyresampled() 3--EXTENSIONS-- 4gd 5--SKIPIF-- 6<?php 7if (!(imagetypes() & IMG_PNG)) { 8 die("skip No PNG support"); 9} 10?> 11--FILE-- 12<?php 13 14echo "Simple test of imagecopyresampled() function\n"; 15 16$dest_lge = dirname(realpath(__FILE__)) . '/imagelarge.png'; 17$dest_sml = dirname(realpath(__FILE__)) . '/imagesmall.png'; 18 19// create a blank image 20$image_lge = imagecreatetruecolor(400, 300); 21 22// set the background color to black 23$bg = imagecolorallocate($image_lge, 0, 0, 0); 24 25// fill polygon with blue 26$col_ellipse = imagecolorallocate($image_lge, 0, 255, 0); 27 28// draw the eclipse 29imagefilledellipse($image_lge, 200, 150, 300, 200, $col_ellipse); 30 31// output the picture to a file 32imagepng($image_lge, $dest_lge); 33 34// Get new dimensions 35$percent = 0.5; // new image 50% of original 36list($width, $height) = getimagesize($dest_lge); 37echo "Size of original: width=". $width . " height=" . $height . "\n"; 38 39$new_width = $width * $percent; 40$new_height = $height * $percent; 41 42// Resample 43$image_sml = imagecreatetruecolor($new_width, $new_height); 44imagecopyresampled($image_sml, $image_lge, 0, 0, 0, 0, $new_width, $new_height, $width, $height); 45 46imagepng($image_sml, $dest_sml); 47 48list($width, $height) = getimagesize($dest_sml); 49echo "Size of copy: width=". $width . " height=" . $height . "\n"; 50 51imagedestroy($image_lge); 52imagedestroy($image_sml); 53 54 55echo "Done\n"; 56?> 57--CLEAN-- 58<?php 59 $dest_lge = dirname(realpath(__FILE__)) . '/imagelarge.png'; 60 $dest_sml = dirname(realpath(__FILE__)) . '/imagesmall.png'; 61 @unlink($dest_lge); 62 @unlink($dest_sml); 63?> 64--EXPECT-- 65Simple test of imagecopyresampled() function 66Size of original: width=400 height=300 67Size of copy: width=200 height=150 68Done 69