code:
//Cut the bottom of the uploaded image and remove the headline watermark function cropUploadImage($upload){ $src_path = $upload['file']; $src = imagecreatefromstring(file_get_contents($src_path)); $x = 0; $y = 0; $width = imagesx( $src ); $height = imagesy( $src )-55; $final_width = $width; $final_height = round($final_width * $height / $width); $new_image = imagecreatetruecolor($final_width, $final_height); imagecopyresampled($new_image, $src, 0, 0, $x, $y, $final_width, $final_height, $width, $height); header('Content-Type: image/jpeg'); imagejpeg($new_image,$src_path); imagedestroy($src); imagedestroy($new_image); return $upload; } add_filter( 'wp_handle_upload', 'cropUploadImage',2 );
Introduction:
-
In code $height = imagesy( $src )-55; , "- 55" adjustable clipping height -
The uploaded image will be cropped from the deployment of this code, -
The picture clipped by this code will not be restored after deleting this code -
It can cooperate with various cloud storage plug-ins
effect:
Deployment location: