I have a function to convert jpg image to tiff image, keep the original size and quality. I used Imagick class to do that. Convert success but image size has increment too much. My original image was taken from iPhone with 2.6Mb after converting, it increment to 36.6Mb.
I had tried to use some PHP image manipulation libraries like Intervention/image but nothing change.
I also test convert original jpg to new jpg and file size increment from 2.6Mb to 3.3Mb.
My code here:
$image = new \Imagick('image_path_file.jpg);
$image->setImageFormat("tiff");
$image->writeImage("path_new_file.tiff");
Have any options that can help Imagick not increment file size too much?
Thanks you 🙇♂️
Related
I am scaling images with php-imagick. The image I want to scale is a jpg without exif data (1600x1200+0+0 8-bit sRGB). The quality of the scaled image is lower than the original. By quality I mean that the image has more artifacts (visible quality). So I made a test where I simply read an image and write it under another filename without chaning anything else:
$im = new Imagick();
$im->readImage(realpath('./a.jpg')); // image quality checked with $im->getImageCompressionQuality() 50
$im->writeImage('./b.jpg'); // image quality checked with $im->getImageCompressionQuality() 50
The result is:
Image a.jpg > 254kb (original image)
Image b.jpg > 183kb
So by simply writing the image to a new file, php-imagick changes something that I don't want.
Can anyone explain to me:
What happens to the generated image?
How can I write the image without changing any other stuff except scaling?
Thanks
I have created images using PHP image GD library and have them stored on my server, For the purpose of keeping some images uncached I wrote php code to fetch some specific images and output the php page as image through php headers:
$image=imagecreatefrompng($image_location);
header("Content-Type: image/png");
imagepng($image);
imagedestroy($image);
surprisingly, the image from php page is always slightly smaller in size than the original static file using which the image was created. Original PNG file was 11.5KB in one case, while the php png file of the same static file was 11.3KB
The original png image was created using
imagecreate(), imagecolorallocate(), imagettftext()
and
imagepng($image,$location,9,PNG_ALL_FILTERS)
Why is the original image itself always bigger than the original? How can I reduce the size first time itself? Is there something "un-optimized" about my code?
Please help me out, even a 10% saving on size will help me hugely.
I am getting Image URL from the DB like this "image01-v2-70-70.jpg".
It is already scaled to 70-70, so I am getting it as smaller image.
I want to scale this image to 120-120 from its default 70-70
Thanks in Advance
You can do this with the help of a php extension php image magick
header('Content-type: image/jpeg');
$image = new Imagick('image01-v2-70-70.jpg');
$image->adaptiveResizeImage(120,120);
echo $image;
But this is highly not recomended as you are going from a smaller resolution to a larger resolution which will make the image blurry.
A piece of advice try to make a copy 120X120 resolution from the original image
I am making an avatar script from scratch and am having some problems. I got transparency working, and multi-image support for heads, bodies, shirts, etc.
Anyhow, I want to be able to generate specific sizes of the avatar within the PHP script. At this time, I have the variable $baseImage, which is an image generated using the GD script below:
$baseImage = imagecreatefrompng($startAsset);
imagealphablending($baseImage, true);
imagesavealpha($baseImage, true);
... combine all images into $base here
header("Content-type: image/png");
imagepng($baseImage);
The size of the image this generates is 350x550 (pixels) and I want to be able to get a smaller size.
I've done research but cannot find a working solution. What built-in PHP GD functions can resize this, retain transparency, and keep the great quality/colors?
There is no way to change the size of an image resource directly. Instead, you need to create a new image of the desired size and use imagecopyresampled to copy from the fullsize image to the resized one.
I'm creating an image editor in JS/PHP, but now I'm having trouble. First of all, I load the image from the database (load a blob with imagecreatefromstring). Then I apply a list of actions to this image. But how can I get the image size from this image handler I have then? Without writing it to a file or use a stream object. How??
In case you mean the image dimensions:
$width = imagesx($imgHandle);
$height = imagesy($imgHandle);
See imagesx() and imagesy().
If you mean filesize, that's not possible without converting the GD resource to some image format (GIF, PNG, JPEG) because the format determines the image size in bytes.
I doubt you can since php gd image object is a generic object, without considerations on the compression that will be used for storage (png/jpg/bmp ...)