Image Manipulation: image resize in kb and save it in PHP
Here you will learn php program code to reduce image resize in kb. User must have to given the source file name and the coordinates to perform this image manipulation program.
Program code of Image resize in kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <?php $sourceFile = "image.jpg"; $targetFile = "resized_image.jpg"; $targetWidth = 800; $targetHeight = 600; list($sourceWidth, $sourceHeight) = getimagesize($sourceFile); $sourceImage = imagecreatefromjpeg($sourceFile); $targetImage = imagecreatetruecolor($targetWidth, $targetHeight); imagecopyresized($targetImage, $sourceImage, 0, 0, 0, 0, $targetWidth, $targetHeight, $sourceWidth, $sourceHeight); imagejpeg($targetImage, $targetFile); imagedestroy($sourceImage); imagedestroy($targetImage); echo "Image resized successfully."; ?> |
Check our other PHP examples