1. <?php
  2. $path = 'images';
  3. $outputPath = 'result';
  4. $files = array_diff( scandir($path), array('.', '..') );
  5. foreach( $files as $file ) {
  6. removeGreenBackground( $file, $path, $outputPath );
  7. }
  8. function removeGreenBackground( $file, $path, $outputPath )
  9. {
  10. $greenscreen = '#00FF00';
  11. $fuzz = 34370;
  12. $image = new Imagick( realpath( $path.'/'.$file ) );
  13. $image->floodFillPaintImage( '#FFFFFF', $fuzz, $greenscreen, 0, 0, false, Imagick::CHANNEL_ALPHA );
  14. /*header('Content-type: image/jpeg');
  15. echo $image;*/
  16. $image->setImageFormat ('jpeg');
  17. file_put_contents( $outputPath.'/custom_'.$file, $image );
  18. }
  19. ?>
Comments powered by Disqus