lundi 31 juillet 2017

Error in adding watermark to large images in Laravel Using Intervention Image

I would like to ask your ideas if what I have gone wrong with the adding of watermark to my images on upload using Intervention/Image in Laravel.

First, I used dropzone to upload multiple files on queue. It worked well according to my preference.

Now, I need to upload at the same time the image with the watermark. I stored the images with watermark to different folder but inline with the folder of original files.

Here is my code for uploading the images:

public function upload(Request $request)
{
    //this upload to original files to the first folder
    $image = $request->file('file');
    $destination = public_path('images/raw');
    imageName = $image->getClientOriginalName();
    $fileType = $image->getMimeType();
    //files are now saved
    $image->move($destination,$imageName);

    //I passed the new destination for watermarked images
    $newD = $destination.'-wmark';

    //I have to check first if the file type is video

    if(strpos($fileType, 'video') === false) {
        $this->makeWaterMark($destination.'/'.$imageName, $newD, $imageName);

    }  
}


public function makeWaterMark($file, $newD, $name)
{

    if(!is_dir($newD)){
        mkdir($newD,0777);
    }

    copy($file, $newD.'/'.$name);

    $newF = $newD.'/'.$name;
    $img = Image::make($newF);
    $img->resize(1850, 1850);
    $img->insert(public_path('images/logo.png'), 'bottom-right', 10, 10); 
    $img->save($newF);
    return $newF; //return value
}

This works with images that has small file sizes, even if I simultaneously upload those images, but if I'm going to upload images that are 3-5mb file size, even only 2 images, I got an internal error. No errors are shown. I don't know why. Is there limitations to resizing or inserting watermarks using Intervention/Image in Laravel.

I really need your help.

Thanks in advance.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire