/** * Checks uploaded file is an image. * * @param mixed $value data to filter * @return mixed filtered value */ protected function doTransform($value) { if (!$value->exists()) { throw new T_Exception_Filter('is not a valid file'); } switch ($value->getMime()->getType()) { case T_Mime::JPEG: $this->assertType($value, IMAGETYPE_JPEG, 'JPEG'); break; case T_Mime::GIF: $this->assertType($value, IMAGETYPE_GIF, 'GIF'); break; case T_Mime::PNG: $this->assertType($value, IMAGETYPE_PNG, 'PNG'); break; default: throw new T_Exception_Filter('must be a JPEG, GIF or PNG image'); } try { $img = new T_Image_GdFile($value); } catch (Exception $e) { throw new T_Exception_Filter('could not be processed (probably too big!)'); } // normalize extension $img->convertTo($img->getMime()->getType()); return $img; }
function testConvertPngToJpg() { $im = new T_Image_GdFile(new T_File_Path($this->getImageDir(), 'w-400-h-300', 'png')); $im->convertTo(T_Mime::JPEG); $this->assertTrue(strlen($im->__toString()) > 0); }