Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

murilo's avatar
Level 10

use Image intervention 3 with Laravel and store at storage path

hello , I am trying to use image intervention 3 and store that in store path in Laravel

If I try to store that at the public path like this , it saves ok -

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);

this is working . it is saving the same path, with diferent name . But what I want is to save in the storage path . does have any way to do something like that ?

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);

it will give this error -

Call to undefined method Intervention\Image\Image::hashName()

0 likes
2 replies
LaryAI's avatar
Level 58

To solve the issue you're encountering with storing an image in the storage path using Laravel and the Intervention Image library, you need to adjust how you handle the image data when saving it to the storage. The error you're seeing (Call to undefined method Intervention\Image\Image::hashName()) occurs because the Storage::putFile() method expects an instance of Illuminate\Http\File or Illuminate\Http\UploadedFile, but you are passing an instance of Intervention\Image\Image.

Instead, you should use the Storage::put() method, which allows you to directly store raw data. You'll need to convert the image to a string format before saving. Here's how you can do it:

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

$oldLocation = public_path("assets/images/test.jpg");
$newLocation = "photos/newImage.jpg"; // Specify the new file name

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

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

// Convert image to string format and save to storage
$imageData = (string) $image->encode('jpg', 90); // Encode the image to JPG with 90% quality
Storage::put($newLocation, $imageData);

Explanation:

  1. Image Encoding: The image is encoded to a string format using $image->encode('jpg', 90). The encode method takes two parameters: the format (e.g., 'jpg', 'png') and the quality (0-100).
  2. Storage::put(): This method is used to store the encoded image data. It takes two parameters: the path where the file should be stored within the storage disk and the data of the file.

This approach should resolve the error and successfully save the modified image to the specified storage path in Laravel.

murilo's avatar
murilo
OP
Best Answer
Level 10

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);

Please or to participate in this conversation.