Reduction of dimensions in a JPEG image - jpeg

I have to reduce the dimensions of a JPG image to exactly 350 * 450 pixels.Please tell how do I do so.My JPG image is of dimensions 392*520 pixels.
UPDATE:
Ok, thanks for the answers . Checking them now.
Thanks.

You can't do that with a linear operation, the ratio of the image will be skewed.
There is nearly 3 % absolute difference, I don't know how much that is to the human perception.
350/392 = 0.8929
450/520 = 0.8654
I would recommend scaling it to 89% and then cut the rest of the image to get your 350 * 450. This way you would keep the ratios intact.

You can use paint. Go to the resize button (on top of the rotate button) and click the radio box that says pixels. Choose the amount of pixels you want.

There are many online resize tools, e.g.: http://www.picresize.com/
Upload your image, enter its new dimensions and download it again.

Related

Extract the 3×3image segment from the input image centred around the position (x,y)

I want to ask how to Extract the a n×n image segment from an input image centered around the position (x,y), the image has format like this [[num,num,num],[num,numm,num],[num,num,num]........], size of image is about 10 * 10. Thank you !
I do really recommend using numpy, when working with multidimensional arrays/when you want to manipulate these arrays, but here you go, a numpy solution and a solution without numpy.
import numpy as np
img = np.array([[1,2,3,4,5],[2,3,4,5,6],[3,4,5,6,7],[4,5,6,7,8],[5,6,7,8,9]])
print('img:\n',img,'\n')
partOfImage = img[0:3,0:3]
print('partOfImage:\n',partOfImage)
img = [[1,2,3,4,5],[2,3,4,5,6],[3,4,5,6,7],[4,5,6,7,8],[5,6,7,8,9]]
noNumpy =[[img[i][j] for j in range(0,3)] for i in range(0,3)]
print(noNumpy)
Question. So you wish to find the center of an image, expand 1 pixel left, left down, down, right down, right, right up, up, and left up to get an image from the middle of your sample. Correct? I do not have a code example, but a conceptual comment.
Fixed spatial images normally start their addressing at upper left for 0,0. Because of their even numbers of pixels approach, it's near-impossible to find a "middle". So finding a "middle pixel" means you need to apply a percentage and choose the nearest "whole pixel" to the choice. Then expand to your 3x3 dimensions.

How to keep the origin image size with different screen

I want to put some images on the screen.Then i choose openseadragon plugin to help me.
But i have two questions by using it.
Each pic is 256*256 size,but on my mac, is always biger than 256. As below pic shows.
I open it on other screens which is bigger than mine, it also show me bigger.
Maybe is the same quesion as question above.
Can any body give me same help?
Thanks very much!
Actually it should be 256 * 256, but acutally 264.74 * 264.74
Is similar to 256,but still bigger.
The closest you're going to get to displaying tiles with a 1/1 ratio of image pixels to screen pixels is by setting the viewer zoom correctly. Since viewer zoom is based on the width of the image, you'll need that value to compute it...something like:
viewer.viewport.zoomTo(imgWidth / viewer.container.clientWidth);

Ghostscript : Crop Certain Area?

I am new to ghostscript.
I have a pdf which contains a card. i want to crop that card out.
Currently with the understanding of document i am only able to convert the pdf to image but have no luck in cropping.
Saw every other related question but there are not working for me.
This is code i used in batch file for converting the pdf to image:
"C:\Program Files\gs\gs9.50\bin\gswin64c.exe" -sDEVICE=png16m -r300 -o c:\users\jen\desktop\pdf.png -f "c:\users\jen\desktop\pdf.pdf
pause
now i don't know how to crop with it too ?
i want to crop at certain postition like: Left:28 Top:524 Width:492.3 Height:161
EDIT
I will be using this in firebase functions.
Example PDF file THE_PDF_TO_CROP. I want to cutout the blue area of pdf to image.
You need to set several parameters; Firstly you need to specify the width and height of the output bitmap. You can use either -dDEVICEHEIGHTPOINTS and -dDEVICEWIDTHPOINTS, or alternatively you can specify the output size in pixels using -g<x>x<y> where and are the number of pixels in the x and y directions. Obviously that will vary depending on the resolution. You can't (obviously) use fractional pixels.
If you use -dDEVICEWIDTHPOINTS and -dDEVICEHEIGHTPOINTS then you also need to set -dFIXEDMEDIA to tell the interpreter not to use the media size from the PDF file instead.
So that shoould create an output bitmap of the correct size. If you try rendering your file using just that, you will see that it renders just a portion of the page from the bottom left. So now you need to shift the content around so that the portion you want lies at the bottom left of the media. You can do that by using the PageOffset PostScript operator.
You haven't given any numbers, nor supplied an example file, so lets say (for the sake of example) that you want to render a 1 inch by 2 inch portion of the document. Lets further say that you the part you want rendered starts 2.5 inches from the left edge, and 1.5 inches from the bottom edge.
A suitable command line would be:
gs -sDEVICEWIDTHPOINTS=72 -dDEVICEHEIGHTPOINTS=144 -dFIXEDMEDIA -r300 -sDEVICE=png16m -o out.png -c "<</PageOffset [-180 -108]>> setpagedevice" -f input.pdf
Note that PDF (and PostScript) units are 1/72 inch so 72 = 1 inch, 144 = 2 inches. You need to shift the origin of the page down and left, which is why the values for PageOffset are negative.
If that doesn't work for you I'll need to see your PDF file and you'll need to tell me which version of Ghostscript you are using.

Image stretch 100% of screen resolution

I thought I would have found the answer to this question long ago, but I just can't seem to find it anywhere and I'm wondering if you could please help.
Put simply, I want an image to stretch (width only) to 100% of the monitor screen resolution.
Here's what I've tried....
style="position:absolute;width:100%"
This simply makes the image 100% the width of its original size.
style="width:100%"
This makes the image stretch to 100% of the website area (in my case 960px). This is not what I want, as I need the image to stretch 100% of the entire monitor resolution.
style="position:fixed;width:100%"
This makes the image stretch to 100% of the monitor area (yay!) but the fixed position of the image causes problems for the webpage. I'd prefer the image was absolute.
Any information you can provide would be greatly appreciated. Thank you.
Put the image in a div and set that div to 100% then set the width of that image to 100% however wouldn't this just stretch the image?

Ignoring touches on transparent areas cocos2dx

I have an image of size 480x800 pixels and there is a icon on one corner which I need to place. What I want is that to ignore all touches on the transparent areas and detect only the area where the icon is.
I found a solution in SO to this problem but it just tells the code to be used. I need to know exactly where to put that code since I am a beginner and don't know much about cocos2d so I expect a step by step solution.
Cocos2d 2.0 - Ignoring touches to transparent areas of layers/sprites
Do not use glReadPixels because it affected by bugs in android drivers. You can translate CCTouch to CCPoint in image coordinates using convertTouchToNodeSpace, and read image pixel at given point.
Create CCImage from file that contains semi-transparent picture, and read one pixel at tap point; it should be {0,0,0,0} for transparent area.
Don't forget to check that tap is not outside picture, and create pixel index in CCImage::getData() array with formulae unsigned index = x * imageWidth + y.

Resources