Intervention / image

PHP Image Processing
https://image.intervention.io
MIT License
13.88k stars 1.5k forks source link

I wold like to know how could I sore the image inside the storage folder in laravel #1345

Closed murilolivorato closed 5 months ago

murilolivorato commented 5 months ago

hello , I am trying to stora inside the laravel storage class ,

this works -

use Intervention\Image\ImageManager;
use Intervention\Image\Drivers\Gd\Driver;

$oldlocation = public_path("assets/images/test.jpg");
$newlocation = public_path("assets/images/test2.jpg");

$manager = new ImageManager(new Driver());

$image = $manager->read($oldlocation);
 $image->scale(width: 300);
$image->save($newlocation);

I need to save inside the laravel storage

I tryed like this -


use Intervention\Image\ImageManager;
use Intervention\Image\Drivers\Gd\Driver;
use Illuminate\Support\Facades\Storage;

$oldlocation = public_path("assets/images/test.jpg");
$newlocation = "photos"

$manager = new ImageManager(new Driver());

$image = $manager->read($oldlocation);
 $image->scale(width: 300);
Storage::putFile($newlocation , $image);

or

use Intervention\Image\ImageManager;
use Intervention\Image\Drivers\Gd\Driver;
use Illuminate\Support\Facades\Storage;
use Intervention\Image\Encoders\AutoEncoder;

$oldlocation = public_path("assets/images/test.jpg");
$newlocation = "photos"

$manager = new ImageManager(new Driver());

$image = $manager->read($oldlocation);
 $image->scale(width: 300);
Storage::putFile($newlocation , $ (string) $image->encode(new AutoEncoder(quality: 65));

but nothis seams to work

murilolivorato commented 5 months ago

I solved like this -

use Intervention\Image\ImageManager;
use Intervention\Image\Drivers\Gd\Driver;
use Illuminate\Support\Facades\Storage;
use Intervention\Image\Encoders\AutoEncoder;

$oldlocation = public_path("assets/images/test.jpg");
$newlocation = "photos"

$manager = new ImageManager(new Driver());

$image = $manager->read($oldlocation);
 $image->scale(width: 300);

  $image->encode(new WebpEncoder(quality: 65)); 
Storage::disk('public')->put('photo.jpg', $image);