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.

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.

index.php

 $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);
    	break;
  	case 'image/gif':
    	$img_water_mark = imagecreatefromgif($wp_src);
    	break;
  	case 'image/png':
    	$img_water_mark = imagecreatefrompng($wp_src);
    	break;
  	default:
    	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;

}
?>


Orignal 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 Image Resize Crop Thumbnail Watermark PHP Script.
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