ys-tinify-laravel icon indicating copy to clipboard operation
ys-tinify-laravel copied to clipboard

Getting error Call to undefined method Tinify\Tinify::fromFile()

Open ManvinderSingh005 opened this issue 5 years ago • 1 comments

Hey, I am new to Laravel environment. Kindly assist me. I have installed your package but i am not able to use it in the controller where i need to compress the images. Can you please assist me how to include the class or method so that i can compress images in controller. Below is the sample code of my public controller that i am trying to do:

namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Http\Requests; use App\Http\Controllers\Controller;

use Tinify\Tinify;

class TinifyController extends Controller {

public function index(){ $uncompressed = public_path("images\uncompressed\img.jpeg"); $compressed = public_path("images\compressed\img.jpeg"); $result = Tinify::fromFile($uncompressed); /** To save as File **/ $result->toFile($compressed); echo "Done!"; die; }

}

ManvinderSingh005 avatar Dec 28 '19 17:12 ManvinderSingh005

This is correct solution to compress image. solved by RJ and AJ use Tinify; // Dont use use Tinify\Tinify;
public function test(){ $image_path = 'Uploads/test.png'; $public_path = public_path($image_path); $result = Tinify::fromFile($public_path);
$result->toFile($public_path); $data = $result->toBuffer(); }

Ajinkya-Naik avatar Jan 18 '20 08:01 Ajinkya-Naik