imagecopyresampled_basic.phpt 1.6 KB

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