imagecopyresampled_basic.phpt 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. --TEST--
  2. imagecopyresampled()
  3. --SKIPIF--
  4. <?php
  5. if (!function_exists('imagecopyresampled')) die('skip imagecopyresampled() not available');
  6. ?>
  7. --FILE--
  8. <?php
  9. /* Prototype : bool imagecopyresampled ( 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 )
  10. * Description: Copy and resize part of an image with resampling.
  11. * Source code: ext/standard/image.c
  12. * Alias to functions:
  13. */
  14. echo "Simple test of imagecopyresampled() function\n";
  15. $dest_lge = dirname(realpath(__FILE__)) . '/imagelarge.png';
  16. $dest_sml = dirname(realpath(__FILE__)) . '/imagesmall.png';
  17. // create a blank image
  18. $image_lge = imagecreatetruecolor(400, 300);
  19. // set the background color to black
  20. $bg = imagecolorallocate($image_lge, 0, 0, 0);
  21. // fill polygon with blue
  22. $col_ellipse = imagecolorallocate($image_lge, 0, 255, 0);
  23. // draw the eclipse
  24. imagefilledellipse($image_lge, 200, 150, 300, 200, $col_ellipse);
  25. // output the picture to a file
  26. imagepng($image_lge, $dest_lge);
  27. // Get new dimensions
  28. $percent = 0.5; // new image 50% of original
  29. list($width, $height) = getimagesize($dest_lge);
  30. echo "Size of original: width=". $width . " height=" . $height . "\n";
  31. $new_width = $width * $percent;
  32. $new_height = $height * $percent;
  33. // Resample
  34. $image_sml = imagecreatetruecolor($new_width, $new_height);
  35. imagecopyresampled($image_sml, $image_lge, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
  36. imagepng($image_sml, $dest_sml);
  37. list($width, $height) = getimagesize($dest_sml);
  38. echo "Size of copy: width=". $width . " height=" . $height . "\n";
  39. imagedestroy($image_lge);
  40. imagedestroy($image_sml);
  41. echo "Done\n";
  42. ?>
  43. --CLEAN--
  44. <?php
  45. $dest_lge = dirname(realpath(__FILE__)) . '/imagelarge.png';
  46. $dest_sml = dirname(realpath(__FILE__)) . '/imagesmall.png';
  47. @unlink($dest_lge);
  48. @unlink($dest_sml);
  49. ?>
  50. --EXPECT--
  51. Simple test of imagecopyresampled() function
  52. Size of original: width=400 height=300
  53. Size of copy: width=200 height=150
  54. Done