Image Resize Crop Thumbnail Watermark PHP Script

Today, We want to share with you Image Resize Crop Thumbnail Watermark PHP Script.In this post we will show you php image resize and save to folder, hear for Copy and resize part of an image using 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.

Image Resize Crop Thumbnail Watermark PHP Script

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

Read Also:  Simple Ecommerce PHP Shopping Cart Application

As I will cover this Post with live Working example to develop php resize image without cropping, so the Resize , compress and add watermark (optional) to an image in php for this example is following below.


function manipulation_img($orignal_src,$destination,$tham_width = 100,$tham_height = 100,$quality = 80,$wp_src = false) {

  $info = getimagesize($orignal_src);
  $imgtype = image_type_to_mime_type($info[2]);

  switch ($imgtype) {
  case 'image/jpeg':
  	$source = imagecreatefromjpeg($orignal_src);
  case 'image/gif':
  	$source = imagecreatefromgif($orignal_src);
  case 'image/png':
  	$source = imagecreatefrompng($orignal_src);
  	die('Sorry Your File type : Invalid image type.');

  $src_w = imagesx($source);
  $src_h = imagesy($source);
  $src_ratio = $src_w/$src_h;

  if ($tham_width/$tham_height > $src_ratio) {
  $thumb_new_height = $tham_width/$src_ratio;
  $new_w = $tham_width;
  } else {
  $new_w = $tham_height*$src_ratio;
  $thumb_new_height = $tham_height;
  $x_mid = $new_w/2;
  $y_mid = $thumb_new_height/2;

  $new_thumb = imagecreatetruecolor(round($new_w), round($thumb_new_height));
  imagecopyresampled($new_thumb, $source, 0, 0, 0, 0, $new_w, $thumb_new_height, $src_w, $src_h);
  $output = imagecreatetruecolor($tham_width, $tham_height);
  imagecopyresampled($output, $new_thumb, 0, 0, ($x_mid-($tham_width/2)), ($y_mid-($tham_height/2)), $tham_width, $tham_height, $tham_width, $tham_height);

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

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

  $wm_x = $tham_width - $wm_w;
  $wm_y = $tham_height - $wm_h;

  imagecopy($output, $img_water_mark, $wm_x, $wm_y, 0, 0, $tham_width, $tham_height);

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

  return false;


<form method="post" enctype="multipart/form-data">
Orignal Image: <input type="file" name="img_file_uploaded" />
<input type="submit" value="Handle This Image" />


if($_FILES) {
  $orignal_src = $_FILES['img_file_uploaded']['tmp_name'];

  $destination = '/www/pakainfo/admin/image/filename.jpg';
  $tham_width = 400;
  $tham_height = 400;
  $quality = 100;

  $wmsource = '/www/pakainfo/admin/img_water_mark/image.png';

  $success = manipulation_img($orignal_src,$destination,$tham_width,$tham_height,$quality,$wmsource);
  if($success) { echo "Good Luck, Your image was saved successfully!"; }
  else { echo "Sorry, Your image was not saved."; }


Angular 6 CRUD Operations Application Tutorials

Read :

Read Also:  PHP File file_get_contents Handling Function


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

I hope you get an idea about Image Resize Crop Thumbnail Watermark PHP Script.
I would like to have feedback on my 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.

Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Get all checked Checkbox Values using VueJS
  2. Read Also:  Laravel Search Comma Separated values Example
  3. Read Also:  PHP image manipulation Fits and Fill
  4. Read Also:  PHP Image Resize, Crop, Thumbnail, Watermark
  5. Read Also:  PHP Image Resize Tutorials
  6. Read Also:  Laravel Resize Image Before Upload Example
  7. Read Also:  PHP Ajax Image Upload Resize Crop using jQuery
  8. Read Also:  PHP Image Resize Script Example
  9. Read Also:  Laravel 6 Deletes method using Eloquent ORM
  10. Read Also:  Creating Custom Database Tables plugin or theme using WordPress