9951 explained code solutions for 126 technologies


php-gdHow to compress GD image


<?php

$im = imagecreatefrompng('/var/www/examples/heroine.png');
imagejpeg($im, '/tmp/image.jpg', 88);ctrl + c
$im

image resource of original image to compress

imagecreatefrompng

creates GD image object from given PNG image

imagejpeg

saves $im gd object to the specified 'jpeg' file with a given level of compression

88

quality (or compression) level, use lower values for better compression, up to 100 (best quality, worst compression)