Write Images (300 DPI) to PDF without losing quality - image

I am using PDFBox library and create a A4 (8.5x11 inches) page size. Now I have images with 2500x3300 size that I want to write on PDF. But pdf size is actually is 612 x 792, how to write 300 DPI images to PDF ?
If I resize image to fit 2500x3300 -> 612x792, it loses quality. There should be some method to write image to pdf whose have 300 DPI.
I am using PDFBox, Please let me know if I missed anything in above explanation
Updated Question:
Let me explain the question in other way I want to provide a customize setting to user to provide the DPI of image with which image will be drawn to PDF. I know PDFBox can write images to PDF but there is no such DPI settings available which I can use to write images to PDF with respect to DPI. Currently I am using PDFBox with is using PDPageContentStream.drawImage(img, , ); but there is no DPI parameter available to write image on PDF. Please tell me method which we can use to draw images to pdf with DPI parameters.
Thanks

If the process does not down sample the image (the number of pixels does not changes), then you are not loosing quality. The resolution may change though if the physical dimensions of the image in the PDF changes but that does not decrease the quality; it just looks smaller or bigger.
If you want the resolution to stay the same, then the physical dimensions of the image in the PDF follows from that:
image width = 2500 / 300 inch = 600 points;
image height = 3300 / 300 inch = 792 points
Your A4:
page width = 8.5 inch = 612 points;
page height = 11 inch = 792 points
That is actually a nice fit.
Add a horizontal translation of 0, 6 or 12 points to horizontally align the image left, center or right.
--- update
You should not consider DPI as a setting when converting a raster image to PDF (or better: when creating a PDF page with an image on it). The DPI follows from the number of pixel rows and columns of the raster image -and- the physical width and height of that image on the PDF page. If you don't touch the image - which I assume because you don't want to loose quality - then you have to choose the physical width and height such that the resultant DPI is as required. DPI = #pixels / inch.

Related

Image number of pictures and dpi

An image is broken down in picture elements (pixels) which means that when I check the attributes of an e.g. JPEG image stored on disk I can see e.g. 532 × 1051 pixels which means the width is 532 the height is 1051.
It also says in the attributes of the file that the color model is RGB which would mean 1 byte for each channel = 3 bytes to describe the color.
So I would assume that the actual size of the image is:
532x1051x3= 1.67MB
But what I see is that the actual file size reported is 45KB.
So does this mean that the 1.67MB is the size of the image in memory?
Also I see as part of the meta data: Image DPI: 96 pixels/inch.
What exactly is this information used for?
But what I see is that the actual file size reported is 45KB
That's because JPEG images are compressed in multiple ways to save up space, sometimes up to a factor of ten so this is not unusual. You can just search for "jpeg compression" and read how it is done in detail if you're interested.
Also I see as part of the meta data: Image DPI: 96 pixels/inch. What
exactly is this information used for?
Generally, as long as you are only interested in the image stored digitally you do not use it at all, because the image is not stored in inches. You could change the DPI and the image itself would not change, just the image header.
DPI only makes sense once you display/print the image. Then you could take it as a general recommendation on which resolution you should print this image. If you want to print a huge landscape with only 50 pixels per inch, it will not look good. If you however want to print a small logo with low DPI it might still look fine. So it really depends highly on the context of the image.

image resolution on website, when resize

I created this image with photoshop 4500x2646px 72dpi, I want to show my picture in a div of 700x412px.
1 resize with photoshop, 700x412px 72dpi quality 12 (max) -> 216Kb and the quality (according to my scale) on my site is 8 (from 0 to 10).
2 resize with photoshop, 1400x824px 72dpi quality 12 (max) -> 683Kb and the quality (according to my scale) on my site is 10 (from 0 to 10).
Why if the browser resize an original image of 1400px to 700px the quality of the pictures are better than use a pictures resize by photoshop ?
The resize method of a browser is better the photoshop ?
I'm using a full hd screen.
Thanks
If you resize a 4500x2646px image with html/css in a Browser, it will still have to download the full image and use bandwidth. It's not like having a server program resize and save a new image like a thumbnail.
It also may depend on what method the specific Browser is using to resample the image, nearest-neighbor or bicubic.
Take a look at the different options in Photoshop for resizing/resampling. And Flatten the image first so that the edges don't blur, then Save As JPEG. But do not save over your PSD as flattened or you won't get your layers back.
There are more quality options if you choose Save for Web.
And if the image is still not crisp enough, I put a Smart Sharpen Filter of 15%, 1.0px Radius.

Image resizing without quality loss?

If I have for example an image of size 400 x 600. I know how to resize it in order to be of size 80 x 80 by using the code below:
original_image = imread(my_image);
original_image_gray = rgb2gray(original_image);
Image_resized = imresize(original_image_gray, [80 80]);
But I think that imresize will resize the image with some losses in the quality. So how to resize it without any loss of the quality?
Image resizing itself will lose part of the image info, i.e. quality of the image.
What you can do is to choose the resizing method that fits your purpose by setting up the corresponding parameter:
[...] = imresize(...,method)
^^^^^^
Matlab stores images as pixel array. It is impossible, to store all the information contained in a 400x600 element matrix in a 80x80 matrix, therefore quality loss is unavoidable when resizing the pixel array, which is what imresize does.
If you want to reduce the physical size of your output, you should look at the imgwrite documentation, in particular at the XResolution and YResolution parameters in the case of creating png images.
original_image = imread(my_image);
imwrite(original_image_grey,'image.png','png','ResolutionUnit','cm','XResolution',400)
The above code will create a png of the original image with a resolution of 400px/cm, resulting in an image of 1cm width. The png will still be a 400x600px Bitmap.

SWFUpload - how to resize image by filling in whitespace if size does not match fixed size

I need to have full original image of any size, resized in to a fixed sized area.
I'm using SWFUpload for this. I haven't figured out how is this possible?
Example
I have image sized 200 X 500 px.
It has to fit to fixed sized image area of 500 X 500 px.
In the end image I'd like to have empty area which is sized of 300 X 0 px to show white background.
Any ideas if this is actually possible?
This is not possible using the current flash api. The latest (beta) version allows only resizing.

How to resize the image width and height with same quality in Corona SDK?

I want to re-size the image for example say 1000 * 1000 to 100 * 100. And I want to display full image after resizing it. Please can anyone help me?
To scale display objects in Corona either use the scale() command or manipulate the xScale and yScale properties:
http://developer.anscamobile.com/node/2452
Note however that the scaling will look best if the image sticks to power of two divisions. That is, 1/2 size, 1/4 size, etc.
For fast animations (eg. the object transitions away over half a second) the exact scaling you describe would look fine, but otherwise I'm wondering why you would want to do that in Corona (as opposed to scaling the image in Photoshop and simply having a smaller image to begin with.)
It'd be best to create an image of a larger size than you'd like to display. This will preserve the quality. For example you have an image with dimensions of 100x100 and you'd like it to display as a 20x20 image. Do the following:
local IMAGE = display.newImageRect("IMAGE.png", 20, 20)

Resources