image resize but without any compromise in DPI?
I want to resize a image w开发者_如何学Goith DPI 300 or greater.. I want it's DPI to remain intact... I have used GD library function to resize image cropped but it brings down DPI to 90! please give a solution as my requirement involves no downsizing of DPI
- Take image, say it's 1000 x 1000 Pixels large
- Crop / resize image to a portio, say, 100 x 100 Pixels large
- Enlarge 100 x 100 portion to 1000 x 1000 Pixels - use
imagecopyresampled()
for best results - manual - Done!
This comes at the price of lower quality, obviously.
It's going to be impossible to enlarge an image with no quality loss. You won't be able to retain the original image quality when enlarging because the pixel information simply isn't there. There are resizing algorithms that employ antialiasing and other techniques (like resampling in imagecopyresampled()
to help the quality, but it will never be perfect.
If you want to display a large image smaller without losing any image data, you would put it into a img
tag and then scale it down using the css width
property. Note: This is not going to give you any better quality than resizing the image. In addition you are transferring more data than necessary, and in some browsers the result of the resizing may look bad due to the use of low-quality (but fast) algorithms - so the image may end up looking worse.
DPI means dots per inch. If you resize the image, the amount of inches stays the same (you show the same image), but the amount of dots goes down (less pixels).
So if you lower the size of the image, you always lower the DPI.
So if you lower the size of the image, you always lower the DPI.
thats not true the DPI is just a "conversion" used when you print something, it says nothing about the quality of the picture onscreen. if you resize a picture (pixelsize that is) the printed versions shrinks the same way if you don't touch the DPI. you could keep the printed size the same, but that would mean lowering the DPI
1200*1200px image with 300dpi is 4"*4" printed
600*600px image with 300dpi is 2"*2"
600*600px image with 150dpi is 4"*4"
if you use imagecopyresampled() the DPI should stay the same in the image
If you want to cropp an image and retain the source image PPI on the cropped area (which will be a new image) you can use Imagick following these steps:
// copy the original source to a new image, on which you'll be working
copy('example_source.jpg', 'example_cropped.jpg');
// set the resource path to work on
$resource = new Imagick('example_cropped.jpg');
// cropp the image
$resource->cropImage($cropp_width, $cropp_height, $left_offset_in_px, $top_offset_in_px);
// save the image (in this case, the same path as the one we're working on)
$resource->writeImage('example_cropped.jpg');
This is the most reasonable method I've found, since imagecopyresampled and imagejpeg seem to change the PPI of an image to the default 96 ppi (even for sources, with 300 ppi).
精彩评论