/** * Returns the path to the library * * @return string */ static function path() { if (self::$path === null) { self::$path = dirname(__FILE__) . DIRECTORY_SEPARATOR; } return self::$path; }
static function get($operationName) { if (!isset(self::$cache[$operationName])) { $opClassName = "WideImage_Operation_" . $operationName; if (!class_exists($opClassName, false)) { $fileName = WideImage::path() . 'Operation/' . $operationName . '.php'; if (file_exists($fileName)) { require_once $fileName; } else { throw new WideImage_UnknownImageOperationException("Can't load '{$operationName}' operation."); } } self::$cache[$operationName] = new $opClassName(); } return self::$cache[$operationName]; }
public static function get($operationName) { $lcname = strtolower($operationName); if (!isset(self::$cache[$lcname])) { $opClassName = 'WideImage_Operation_' . ucfirst($operationName); if (!class_exists($opClassName, false)) { $fileName = WideImage::path() . 'Operation/' . ucfirst($operationName) . '.php'; if (file_exists($fileName)) { require_once $fileName; } elseif (!class_exists($opClassName)) { throw new WideImage_UnknownImageOperationException("Can't load '{$operationName}' operation."); } } self::$cache[$lcname] = new $opClassName(); } return self::$cache[$lcname]; }
/** * Returns a mapper, based on the $uri and $format * * @param string $uri File URI * @param string $format File format (extension or mime-type) or null * @return WideImage_Mapper **/ static function selectMapper($uri, $format = null) { $format = self::determineFormat($uri, $format); if (array_key_exists($format, self::$mappers)) { return self::$mappers[$format]; } $mapperClassName = 'WideImage_Mapper_' . $format; if (!class_exists($mapperClassName, false)) { $mapperFileName = WideImage::path() . 'Mapper/' . $format . '.php'; if (file_exists($mapperFileName)) { require_once $mapperFileName; } } if (class_exists($mapperClassName)) { self::$mappers[$format] = new $mapperClassName(); return self::$mappers[$format]; } throw new WideImage_UnsupportedFormatException("Format '{$format}' is not supported."); }
<?php /** * @author Gasper Kozak * @copyright 2007-2011 **/ include_once WideImage::path() . '/vendor/de77/TGA.php'; /** * Mapper support for TGA. */ class WideImage_Mapper_TGA { public function load($uri) { return WideImage_vendor_de77_TGA::imagecreatefromtga($uri); } public function loadFromString($data) { return WideImage_vendor_de77_TGA::imagecreatefromstring($data); } public function save($handle, $uri = null) { throw new WideImage_Exception("Saving to TGA isn't supported."); } }
<?php /** Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA **/ include WideImage::path() . 'Mapper/GD.php'; class WideImage_Mapper_GD_Test extends WideImage_TestCase { /** * @var WideImage_Mapper_GD */ protected $mapper; public function setup() { $this->mapper = WideImage_MapperFactory::selectMapper(null, 'gd'); } public function teardown() { $this->mapper = null; if (file_exists(IMG_PATH . 'temp/test.gd')) { unlink(IMG_PATH . 'temp/test.gd'); } } public function testSaveAndLoad() { $handle = imagecreatefromgif(IMG_PATH . '100x100-color-hole.gif'); $this->mapper->save($handle, IMG_PATH . 'temp/test.gd'); $this->assertTrue(filesize(IMG_PATH . 'temp/test.gd') > 0); imagedestroy($handle); // file is a valid image
it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. WideImage is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with WideImage; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * @package Tests **/ include WideImage::path() . 'Mapper/PNG.php'; /** * @package Tests */ class WideImage_Mapper_PNG_Test extends WideImage_TestCase { protected $mapper; function setup() { $this->mapper = WideImage_MapperFactory::selectMapper(null, 'png'); } function teardown() { $this->mapper = null; if (file_exists(IMG_PATH . 'temp/test.png')) { unlink(IMG_PATH . 'temp/test.png');
it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. WideImage is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with WideImage; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * @package Internal/Mappers **/ include_once WideImage::path() . '/vendor/JPEXS/bmp.php'; /** * Mapper support for BMP * * Code used with permission from JPEXS * http://www.jpexs.com/php.html * * @package Internal/Mappers */ class WideImage_Mapper_BMP { function load($uri) { return imagecreatefrombmp($uri); } function save($handle, $uri = null)
it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. WideImage is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with WideImage; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * @package Tests **/ include WideImage::path() . 'Mapper/BMP.php'; /** * @package Tests */ class WideImage_Mapper_BMP_Test extends WideImage_TestCase { /** * @var WideImage_Mapper_BMP */ protected $mapper; function setup() { $this->mapper = WideImage_MapperFactory::selectMapper(null, 'bmp'); } function teardown() {
<?php /** Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA **/ include WideImage::path() . 'Mapper/TGA.php'; /** * @group mapper */ class WideImage_Mapper_TGA_Test extends WideImage_TestCase { /** * @var WideImage_Mapper_TGA */ protected $mapper; public function setup() { $this->mapper = WideImage_MapperFactory::selectMapper(null, 'tga'); } public function teardown() { $this->mapper = null; } public function testLoad() { $handle = $this->mapper->load(IMG_PATH . 'splat.tga'); $this->assertTrue(is_resource($handle)); $this->assertEquals(100, imagesx($handle)); $this->assertEquals(100, imagesy($handle)); imagedestroy($handle);