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
Related
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 🙇♂️
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 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 had troubles resizing a PNG and maintaining small file sizes. Solution found here.
When resizing the PNG, however, I ran into problems regarding image quality. As far as I could see, GD uses indexed 8-bit-color palette which distorts text and colors get lost, see:
Original Image
Resized Image with solution given above
Resized Image with a tweak²
²The idea for the tweak I found here in stackoverflow: Create truecolor-image, resize it, and copy it to a new image, so the palette is determined based on the resampled result and the image quality is better as you can see in the image above.
// create new image
$newImageTmp = imagecreatetruecolor($newwidth,$newheight);
// we create a temporary truecolor image
// do the image resizing by copying from the original into $newImageTmp image
imagecopyresampled($newImageTmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
// create output image
$newImage = imagecreate($newwidth,$newheight);
// copy resized truecolor image onto index-color image
imagecopy($newImage,$newImageTmp,0,0,0,0,$newwidth,$newheight);
// write image to buffer and save in variable
ob_start(); // stdout --> buffer
imagepng($newImage,NULL,6);
$newImageToSave = ob_get_contents(); // store stdout in $newImageToSave
ob_end_clean(); // clear buffer
// remove images from php buffer
imagedestroy($src);
imagedestroy($newImageTmp);
imagedestroy($newImage);
Problem: None of both results are satisfactory.
I am quite sure that there must be a way to 1. determine the color palette, and 2. maintain most of the image's colors, so that 3. the PNG looks similar to the original and has an acceptable file size.
Now, I only see going for JPG instead of PNG. But if you know a solution, it would greatly be appreciated if you let me/us know.
Thank you!
All you need is to replace
$newImage = imagecreate($newwidth,$newheight);
With
$newImage = imagecreatetruecolor($newwidth, $newheight);
Output $maxImgWidth = 200;
PHP's fork of GD doesn't have usable palette generation, so you only get PNG32 with vanialla libpng compression.
For small PNG8 with palette use pngquant, e.g. http://pngquant.org/php.html
And then compress it further with advpng or zopfli-png.
i want to display images like facebook find friends page. i dont want to crop an image. want to reduce size of image.and maintains its actuall appereance.how i can do this.
I recommend the IMagick extension for PHP since it's light on resources and easy to use. The GD extension comes bundled with PHP, but is harder to use and uses a lot of memory.
Here's an example for IMagick:
<?php
header('Content-type: image/jpeg');
$image = new Imagick('image.jpg');
$image->thumbnailImage(100, 100, true);
echo $image;
?>
i dont want to crop an image. want to reduce size of image.and maintains its actuall appereance.
If the actual image size is 128*128 pixel you can use
<img src="..." height="64px" />
"actuall appereance." i think you are talking bout ratio ?