mercredi 1 septembre 2021

Laravel 5 using Intervention with Post Model

Hi I am not having much luck to try and use Intervention with an Image model. Really beginner to this, and have tried many many many changes to the code but not finding result, I have tried also to read online how to pass Intervention into model or model into Intervention but cannot find many information. I am trying only to add a watermark to uploaded images. The code works and image uploads but no watermark on image. Thank you for help! I include snippet of controller function (hope is enough). PostImage is model.

 $file_name = '';

   if ($request->hasFile('image')) {
       $post->has_image = 1;
       $file = $request->file('image');
       $file_name = md5(uniqid() . time()) . '.' . $file->getClientOriginalExtension();

       if ($file->storeAs('/posts/', $file_name)){
           $process = true;
       } else {
           $process = false;
       }
   }else{
       $process = true;
   }

   if ($process) {    
      if ($post->save()){
          if ($post->has_image == 1) {                                         
              $intervention_file = $file;
              $watermark = url('/assets/media/icons/socialbuttons/user.png');
                     
              $intervention = Image::make($intervention_file);
              $intervention->insert($watermark, 'bottom-right', 50, 50);
              $intervention->resize(400,400);
              $intervention->text('Hello, World', 50, 50, function($font){
                  $font->size(50);
                  $font->color("#ffb00");
                  $font->align('center');
                  $font->valign('top');
              });
              $intervention_file_name = md5(uniqid() . time()) . '.' . $intervention_file->getClientOriginalExtension();
              $intervention_file->storeAs('/posts/', $intervention_file_name);
                        
              if ($intervention->save()){
                 $post_image = new PostImage();
                 $post_image->image_path = $intervention_file_name;
                 $post_image->post_id = $post->id;                            
              }
                        
              if ($post_image->save()){
                  $response['code'] = 200;
              }


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3mWkHir
via IFTTT

Aucun commentaire:

Enregistrer un commentaire