imagecopyresampled_basic.phpt 2.1 KB

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