1--TEST-- 2Test format support in writeImageFile 3--SKIPIF-- 4<?php 5 require_once(dirname(__FILE__) . '/skipif.inc'); 6 checkFormatPresent('png'); 7 checkFormatPresent('jpg'); 8?> 9--FILE-- 10<?php 11 12define ("JPEG_FILE", dirname (__FILE__) . "/imagick_test.jpg"); 13define ("PNG_FILE",dirname (__FILE__) . "/imagick_test.png"); 14 15$im = new imagick ('magick:rose'); 16$im->writeImage (JPEG_FILE); 17$im->clear (); 18 19// This is the problematic case, setImageFormat doesn't really 20// affect writeImageFile. 21// So in this case we want to write PNG but file should come out 22// as JPEG 23$fp = fopen (PNG_FILE, "w+"); 24$im->readImage (JPEG_FILE); 25$im->setImageFormat ('png'); 26$im->writeImageFile ($fp); 27$im->clear (); 28fclose ($fp); 29 30// Output the format 31$identify = new Imagick (PNG_FILE); 32echo $identify->getImageFormat () . PHP_EOL; 33 34// Lets try again, setting the filename rather than format 35// This should cause PNG image to be written 36$fp = fopen (PNG_FILE, "w+"); 37$im->readImage (JPEG_FILE); 38$im->setImageFilename ('png:'); 39$im->writeImageFile ($fp); 40$im->clear (); 41fclose ($fp); 42 43// If all goes according to plan, on second time we should get PNG 44$identify = new Imagick (PNG_FILE); 45echo $identify->getImageFormat () . PHP_EOL; 46 47// Lastly, test the newly added format parameter 48$fp = fopen (PNG_FILE, "w+"); 49$im->readImage (JPEG_FILE); 50$im->writeImageFile ($fp, 'png'); 51$im->clear (); 52fclose ($fp); 53 54// If all goes according to plan, on second time we should get PNG 55$identify = new Imagick (PNG_FILE); 56echo $identify->getImageFormat () . PHP_EOL; 57 58unlink (PNG_FILE); 59unlink (JPEG_FILE); 60 61echo 'done' . PHP_EOL; 62?> 63--EXPECT-- 64JPEG 65PNG 66PNG 67done