I have read the documentations on image intervention implementation on laravel and i did it successfully i have also read the documentations on how to use the intervention but i can't seems to figure out how to convert all uploaded images to jpg and to save them to desired path with .jpg extension.
This is my code so far, it's working but with few glitches.
Image::make(Input::file('avatarfull'))->fit('192', '192')->save(base_path() . '/img/' . $imagename .'.jpg')->encode('jpg', 80);
So what i want to achieve is:
This is all from documentation from intervention website.
But in the proccess something gets wrong so i end up with image with no extension at all in my img folder and images doesn't get converted to jpg format. If i upload png it stays png.
For the record i decided to use random string for uploaded images, so
$imagename = str_random(20);
Because i saw that my images get's saved only with random string name, so with uploaded image i end up with a name like:
MSm72XvEWE8AlCUvpHvX
I decided to add .jpg extension manually as you can see
->save(base_path() . '/img/' . $imagename .'.jpg')
And this saves the image with a random string name and .jpg extension at the end.
But problem with converting images to jpg still exists so when i upload png image i get now MSm72XvEWE8AlCUvpHvX.jpg but when i check the image in browser it have transparent background, when i checked properties the image is still png, it just have forced .jpg name because i added that to the save().
Is there a way so all the images gets converted to jpg and also to automatically write the image name with .jpg extension or i have to name that manually ?
I think you need to call encode()
before you call save()
as save actually saves the image to disk.
$jpg = (string) Image::make('public/foo.png')->encode('jpg', 75);
Documentation: http://image.intervention.io/api/encode
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With