How can I cut the image from below using PHP?

I want to take out the text at the bottom of the image. How can I cut it from the bottom ... say 10 pixels to cut from the bottom.

I want to do this in PHP. I have many images with text below.

Is there any way to do this?

+4
source share
2 answers

Here you go.

To change the image name, change $ in_filename (currently 'source.jpg'). You can also use URLs, although obviously this will be worse.

Change the $ new_height variable to set how much of the bottom you want to crop.

Play with the values ​​$ offset_x, $ offset_y, $ new_width and $ new_height, and you will understand this.

Please let me know that this works. :)

Hope this helps!

<?php $in_filename = 'source.jpg'; list($width, $height) = getimagesize($in_filename); $offset_x = 0; $offset_y = 0; $new_height = $height - 15; $new_width = $width; $image = imagecreatefromjpeg($in_filename); $new_image = imagecreatetruecolor($new_width, $new_height); imagecopy($new_image, $image, 0, 0, $offset_x, $offset_y, $width, $height); header('Content-Type: image/jpeg'); imagejpeg($new_image); ?> 
+18
source

You can use the GD Image Library to manage your images in PHP. The function you are looking for is imagecopy() , which copies part of the image to another. Here is an example from PHP.net that does something like what you describe:

 <?php $width = 50; $height = 50; $source_x = 0; $source_y = 0; // Create images $source = imagecreatefromjpeg('source.jpg'); $new = imagecreatetruecolor($width, $height); // Copy imagecopy($source, $new, 0, 0, $source_x, $source_y, $width, $height); // Output image header('Content-Type: image/jpeg'); imagejpeg($new); ?> 

To crop the original image, change the variables $source_x and $source_y to your liking.

+5
source

Source: https://habr.com/ru/post/1302239/


All Articles