public function testFromFileShouldReturnSource() { CurlMock::register("https://api.tinify.com/shrink", array("status" => 201, "headers" => array("Location" => "https://api.tinify.com/some/location"))); Tinify\setKey("valid"); $this->assertInstanceOf("Tinify\\Source", Tinify\fromFile($this->dummyFile)); }
function tinify_image($filepath) { $source = \Tinify\fromFile($filepath); $source->toFile($filepath); }
public static function setUpBeforeClass() { \Tinify\setKey(getenv("TINIFY_KEY")); $unoptimizedPath = __DIR__ . "/examples/voormedia.png"; self::$optimized = \Tinify\fromFile($unoptimizedPath); }
/** * Reduce image size and optimize the image quality * * @TODO Find an faster image optimization solution * @author salvipascual * @param String $imagePath, path to the image * */ public function optimizeImage($imagePath, $width = false, $height = false) { \Tinify\setKey("XdzvHGYdXUpiWB_fWI2muKXgV3GZVXjq"); // load and optimize image $source = \Tinify\fromFile($imagePath); // scale image based on width if ($width && !$height) { $source = $source->resize(array("method" => "scale", "width" => $width)); } // scale image based on width if (!$width && $height) { $source = $source->resize(array("method" => "scale", "height" => $height)); } if ($width && $height) { $source = $source->resize(array("method" => "cover", "width" => $width, "height" => $height)); } // save the optimized file $source->toFile($imagePath); }
public function tinify() { if (!$this->needTinify()) { return false; } $filename = $this->file_info->getPathname(); $source = \Tinify\fromFile($filename); $source->toFile($filename); clearstatcache(true, $filename); $this->file_size = $this->file_info->getSize(); $this->file_info = null; return $this->save(); }
function png2Tiny($pngName, $tinyPng) { \Tinify\setKey("_CU-TGu6JmRws3B9ONb90bcfIcHveuMQ"); $source = \Tinify\fromFile($pngName); $newFile = $dstPath . $pngName; $source->toFile($tinyPng); }