Ejemplo n.º 1
0
 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));
 }
Ejemplo n.º 2
0
 function tinify_image($filepath)
 {
     $source = \Tinify\fromFile($filepath);
     $source->toFile($filepath);
 }
Ejemplo n.º 3
0
 public static function setUpBeforeClass()
 {
     \Tinify\setKey(getenv("TINIFY_KEY"));
     $unoptimizedPath = __DIR__ . "/examples/voormedia.png";
     self::$optimized = \Tinify\fromFile($unoptimizedPath);
 }
Ejemplo n.º 4
0
 /**
  * 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);
 }
Ejemplo n.º 5
0
 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();
 }
Ejemplo n.º 6
-1
function png2Tiny($pngName, $tinyPng)
{
    \Tinify\setKey("_CU-TGu6JmRws3B9ONb90bcfIcHveuMQ");
    $source = \Tinify\fromFile($pngName);
    $newFile = $dstPath . $pngName;
    $source->toFile($tinyPng);
}