PHP Image Resize, Crop, Thumbnail, Watermark

Today, We want to share with you PHP Image Resize, Crop, Thumbnail, Watermark manipulation.In this post we will show you php resize image before move_uploaded_file, hear for Resize , compress and add watermark (optional) to an image in php we will give you demo and example for implement.In this post, we will learn about Resizing and cropping image with GD while retaining aspect ratio with an example.

PHP Image Resize, Crop, Thumbnail, Watermark manipulation

There are the Following The simple About PHP Image Resize, Crop, Thumbnail, Watermark manipulation Full Information With Example and source code.

As I will cover this Post with live Working example to develop laravel intervention image upload, so the php image resize on upload for this example is following below.

index.php

 $src_ratio) {
  $new_h = $dest_width/$src_ratio;
  $new_w = $dest_width;
  } else {
  $new_w = $dest_height*$src_ratio;
  $new_h = $dest_height;
  }
  $x_mid = $new_w/2;
  $y_mid = $new_h/2;
  $newpic = imagecreatetruecolor(round($new_w), round($new_h));
  imagecopyresampled($newpic, $source, 0, 0, 0, 0, $new_w, $new_h, $src_w, $src_h);
  $final = imagecreatetruecolor($dest_width, $dest_height);
  imagecopyresampled($final, $newpic, 0, 0, ($x_mid-($dest_width/2)), ($y_mid-($dest_height/2)), $dest_width, $dest_height, $dest_width, $dest_height);

  if($wmsource) {
  $info = getimagesize($wmsource);
  $imgtype = image_type_to_mime_type($info[2]);
  switch ($imgtype) {
    case 'image/jpeg':
      $img_wmarks = imagecreatefromjpeg($wmsource);
      break;
    case 'image/gif':
      $img_wmarks = imagecreatefromgif($wmsource);
      break;
    case 'image/png':
      $img_wmarks = imagecreatefrompng($wmsource);
      break;
    default:
      die('Invalid img_wmarks type.');
  }

  $wm_w = imagesx($img_wmarks);
  $wm_h = imagesy($img_wmarks);

  $wm_x = $dest_width - $wm_w;
  $wm_y = $dest_height - $wm_h;

  imagecopy($final, $img_wmarks, $wm_x, $wm_y, 0, 0, $dest_width, $dest_height);
  }

  if(Imagejpeg($final,$destination,$quality)) {
  return true;
  }

  return false;
}
?>

Source Image:
Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about PHP Image Resize, Crop, Thumbnail, Watermark manipulation.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment