--- /dev/null
+<?php
+
+class IPF_Image_Processor
+{
+ private $calls = array();
+
+ public static function create()
+ {
+ return new IPF_Image_Processor;
+ }
+
+ public function __call($name, $args)
+ {
+ $this->calls[] = array($name, $args);
+ return $this;
+ }
+
+ private function play($image)
+ {
+ foreach ($this->calls as $call) {
+ list($method, $args) = $call;
+ $image = call_user_func_array(array($image, $method), $args);
+ }
+ return $image;
+ }
+
+ public function execute($sourceUrl, $directory, $root=null)
+ {
+ if ($root === null)
+ $root = IPF::get('upload_path') . DIRECTORY_SEPARATOR;
+
+ $destinationUrl = IPF_Utils::insertDirectory($sourceUrl, $directory);
+ $path = $root . $destinationUrl;
+ if (!is_file($path)) {
+ IPF_Utils::makeDirectories(dirname($path));
+ $image = IPF_Image::load($root . $sourceUrl);
+ $image = $this->play($image);
+ $image->save($path);
+ }
+ return $destinationUrl;
+ }
+}
+
--- /dev/null
+<?php
+
+class Image_Processor_Test extends PHPUnit_Framework_TestCase
+{
+ protected function setUp()
+ {
+ $this->root = IPF::get('upload_path');
+ IPF_Utils::removeDirectories($this->root . '/thumbs');
+ }
+
+ protected function tearDown()
+ {
+ IPF_Utils::removeDirectories($this->root . '/thumbs');
+ }
+
+ public function testRecording()
+ {
+ $url = IPF_Image_Processor::create()
+ ->thumbnailCrop(250, 125, 0.2, 0.2)
+ ->fit(200, 200)
+ ->execute('ipflogo.gif', 'thumbs');
+ $this->assertEquals('thumbs/ipflogo.gif', $url);
+ $this->assertFileExists($this->root . '/thumbs/ipflogo.gif');
+ }
+
+ public function testBackground()
+ {
+ $url = IPF_Image_Processor::create()
+ ->thumbnailFill(250, 125, 0x0F0000FF)
+ ->execute('ipflogo.gif', 'thumbs');
+ $this->assertEquals('thumbs/ipflogo.gif', $url);
+ $this->assertFileExists($this->root . '/thumbs/ipflogo.gif');
+ }
+}
+