10 self::$TempDir =
"tmp/Image--Test-".getmypid();
11 mkdir(self::$TempDir);
19 $Files = glob(self::$TempDir.
"/*");
20 foreach ($Files as $File)
27 rmdir(self::$TempDir);
32 # construct Image with invalid file 33 $BadImage =
new Image(
"abc123");
36 # Test SaveAs() and Status() with no file changes 37 $ImageJpg =
new Image(
"lib/ScoutLib/tests/files/TestImage--600x400.jpg");
38 $ImageJpg->SaveAs(self::$TempDir.
"/TestImage2--600x400.jpg");
39 $this->assertEquals($ImageJpg->Status(),
AI_OKAY,
"Testing SaveAs() for JPG");
41 # Test Xsize() and Ysize() of 600x400 JPG image. 42 $this->assertEquals($ImageJpg->XSize(), 600,
43 "Testing Xsize() of 600px width image");
44 $this->assertEquals($ImageJpg->YSize(), 400,
45 "Testing Ysize() of 400px height image");
47 # Test ScaleTo() without maintaining aspect ratio and converting 49 $ImageJpg->ScaleTo(100, 200);
50 $ImageJpg->SaveAs(self::$TempDir.
"/TestImage--100x200.gif",
53 $ImageGif =
new Image(self::$TempDir.
"/TestImage--100x200.gif");
54 $this->assertEquals($ImageGif->Status(),
AI_OKAY,
"Testing SaveAs() for GIF");
55 $this->assertEquals($ImageGif->XSize(), 100,
56 "Testing ScaleTo() of 100px width image");
57 $this->assertEquals($ImageGif->YSize(), 200,
58 "Testing ScaleTo() of 200px height image");
60 # Test ScaleTo() with maintaining aspect ratio and converting image to png 61 # Because the aspect ratio is maintained, we should expect a 200x400 image. 62 $ImageGif->ScaleTo(200, 300, TRUE);
63 $ImageGif->SaveAs(self::$TempDir.
"/TestImage--200x400.png",
66 $ImagePng =
new Image(self::$TempDir.
"/TestImage--200x400.png");
67 $this->assertEquals($ImagePng->Status(),
AI_OKAY,
"Testing SaveAs() for PNG");
68 $this->assertEquals($ImagePng->XSize(), 200,
69 "Testing ScaleTo() of 200px width image, with aspect ratio maintained");
70 $this->assertEquals($ImagePng->YSize(), 400,
71 "Testing ScaleTo() of 400px height image, with aspect ratio maintained");
73 # Test CropTo() and converting image to bmp 74 $ImagePng->CropTo(100, 150);
75 $ImagePng->SaveAs(self::$TempDir.
"/TestImage--100x150.bmp");
77 $ImageBmp =
new Image(self::$TempDir.
"/TestImage--100x150.bmp");
78 $this->assertEquals($ImageBmp->Status(),
AI_OKAY,
"Testing SaveAs() for BMP");
79 $this->assertEquals($ImageBmp->XSize(), 100,
80 "Testing CropTo() of 100px width image");
81 $this->assertEquals($ImageBmp->YSize(), 150,
82 "Testing CropTo() of 150px height image");
86 $this->assertEquals($ImageJpg->Type(self::$TempDir.
"/TestImage2--600x400.jpg"),
88 $this->assertEquals($ImageJpg->Type(self::$TempDir.
"/TestImage--100x200.gif"),
90 $this->assertEquals($ImageJpg->Type(self::$TempDir.
"/TestImage--100x150.bmp"),
92 $this->assertEquals($ImageJpg->Type(self::$TempDir.
"/TestImage--200x400.png"),
95 "Testing Type() with 'FakeFile.xyz'");
98 $this->assertEquals($ImageJpg->Mimetype(),
"image/jpeg",
99 "Testing Mimetype() for jpg image");
100 $this->assertEquals($ImageGif->Mimetype(),
"image/gif",
101 "Testing Mimetype() for gif image");
102 $this->assertEquals($ImageBmp->Mimetype(),
"image/bmp",
103 "Testing Mimetype() for bmp image");
104 $this->assertEquals($ImagePng->Mimetype(),
"image/png",
105 "Testing Mimetype() for png image");
108 $this->assertEquals($ImageJpg->Extension(),
"jpg",
"Testing Extension()");
110 # Test ExtensionForType() 112 "Testing ExtensionForType() with jpg");
114 "Testing ExtensionForType() with gif");
116 "Testing ExtensionForType() with bmp");
118 "Testing ExtensionForType() with png");
120 "Testing ExtensionForType() with 123");
123 $this->assertEquals($ImageJpg->JpegQuality(50), 50,
124 "Testing JpegQuality() with 80");
126 # Test SupportedFormats() 127 # we assume that jpeg, gif, bmp, and png images will all be supported 130 "Testing SupportedFormats()");
132 # Test SupportedFormatNames() 133 # we assume that jpeg, gif, bmp, and png images will all be supported 135 "Testing SupportedFormatNames contains 'JPG'");
137 "Testing SupportedFormatNames contains 'GIF'");
139 "Testing SupportedFormatNames contains 'BMP'");
141 "Testing SupportedFormatNames contains 'PNG'");
143 # Test SaveAs() error checking 144 $ImageJpg->SaveAs(self::$TempDir.
"/TestImage--100x200.gif",
147 "Testing SaveAs() with AI_UNSUPPORTEDFORMAT");
static SupportedFormatNames()
static tearDownAfterClass()
Destroy sandbox folder and contents.
static setUpBeforeClass()
Create sandbox folder for storing new images.
static ExtensionForType($Type)
return the file name extension for the image, given a type.
static SupportedFormats()
const AI_UNSUPPORTEDFORMAT