resize image to specific height and width value using im4java? - imagemagick

I need to re-size image to any specific height and width value. But I'm not getting resized result. here is my code, please tell me either i'm doing something wrong or missing something.
IMOperation operationSmall = new IMOperation();
operationSmall.addImage("conf/error.png");
operationSmall.resize(300, 1000); // w*h
operationSmall.addImage("conf/errir_small.png");
Original Image size: 1280x960 px.
re-sized image size: 300x225
I tried to give different values, I'm only having issues in height.
their doc is not complete and no code example I find on internet except that using scale (it skip filtering) may solve this problem. but how to use scale in code I have not idea.

I don't read or understand java much, but at the command-line you need an exclamation mark to force ImageMagick to disregard aspect ratio and resize to exact/specific dimensions, like this:
convert -resize 300x200! image....
In the Java docs, there seems to be an option of adding a special 3rd parameter, so I guess you may need
operationSmall.resize(300,1000,'!');
or something similar... or maybe Java uses double quotes rather than the single quotes I suggested.

Related

Dart - How to get the Image height and width of a png file?

Is there a way in getting this sizes? Using command line. Thanks in advance. and can I ask something good tutorials in Dart?
I don't know a built-in feature that allows to do that except readying the content byte-wise and interpreting the values like explained for C++ in C++ How to get the Image size of a png file (in directory)
The image package seems to provide this functionality though. decodePng returns an image that has a width and height property.
The build-in function decodeImageFromList() can help you with that. Its callback contains an Image that includes the width and height.

Webmatrix - webimage crop then resize

I want to make sure that all the images that users upload to my website are the same size.
The size that I want to achieve is 620px x 405px
Because I don't want any white space in my images, and I want to keep the aspect ratio, I'm guessing I'll need to crop first, before I resize?
So far I've got the following code:
photo.Resize(width: 620, height:405, preserveAspectRatio: false, preventEnlarge: true);
But obviously this isn't giving me the desired affect.
I have seen other articles online where they do some formula, but I can't get any to work for me.
Suppose someone uploads an image which is 1020 wide by 405? Which bit do you want to keep? The left hand end? Right hand end? The middle bit? Then the next image is 3000 x 3000. Now which bit do you want to crop? Perhaps this one needs resizing before cropping otherwise you might only get a window.
My recommendation is to allow the user to specify the crop area, and then you resize the resulting cropped image. There are a number of jQuery plugins that enable client side cropping. I've written about jCrop (http://www.mikesdotnetting.com/Article/161/WebMatrix-Testing-the-WebImage-Helper-With-JCrop) but I have also received some feedback that it is not reliable in some versions of IE (although I haven't tested that myself).

Java Server Based Highcharts and width limitation

We started to use highcharts on server side. And I found a limitation of image width.
http://www.highcharts.com/component/content/article/2-news/52-serverside-generated-charts
width Set the exact pixel width of the exported image or pdf. This overrides the -scale parameter. The maximum allowed width is 2000px
Can it be changed in some config files or it's hard-coded thing. If so, why?
Thank you
You can changed in the ExportController.java file, in the Highcharts-export-web module.
Change this line here to alter the maximum allowed width.
It's not a bad idea to have this in a property file, but on the other hand, exporting images bigger than 2000px is also a bit rare.

Exporting chart with Highchart display a badly formed chart

Playing around with HighChart, I am unable to make a user-friendly export, when i export my chart, all data are too compressed to be human readable,bar are too clause from each others. See image at bottom.
I have try to use ChartOption, export, width, scale, but didn't work at this time.
Can somebody propose me an idea?
You can define size (width,
height, scale) of your exporting file.
Ok i got it, As you said Sebastian Bochan we can play with the size in exporting option, but width, height, scale are usefull for resolution but it was not the real width of the exported img.
We have to use sourceWidth, because after digging in exporting.js I noticed that by default if exporting JS is unable to retrieve the size of a chart, it assume 600*600, that was my problem, and that's why my chart look compressed.
By explicitly defining the size with SOURCEWIDTH you can bypass this behavior, but i didn't find why exporting.js is unable to retrieve the original size by himself....
but now i have a full of beauty chart with 60 bar displayed over 1400px, i'm happy !
Thanks for your answer,

Calculate the height and width of image from the source file

I need to calculate the image width and height from the actual image file, so I'm reading the image with open file. so I have bunch of characters and numbers and everything that seems meaningless and they are presenting rgb information probably.
I just want to calculate the size of the image with the raw file information
I am programming in Erlang language but the code in any language will help as we are working with raw file as long as we don't use built-in libraries.
Thank you all in advance for help
I found the answer by going to details of each format,
So it works like this
JPG : you can find the width and height after the bytes "255,192,0,17,8" after that its the information for size
PNG : you can find it after "IHDR"
GIF : you can find it after "GIF89a"
there are information for more but this is the most common image types on internet
Thank you all for your time
I assume when you say 'raw' you mean you only have the pixel values.
In this case there isn't always a way to know the width and height.
Say you read 400 pixels. In this case a valid image side may be any whole factorization of 400, e.g. 1x400, 2x200, 4x100, 8x50, 20x20 etc. and transposed as well.
Not to mention the fact that many image formats include some padding for pixel rows that are not multiples of 4, 8 or 16...
The way it is coded in the image file depend on the image type, which hopefully is also coded in the image file. you can have a look at the question Getting Image size of JPEG from its binary for an example with JPEG coding.
If your data is unknown, use Octave and load the image. Then take a look at this page:
http://www.gnu.org/software/octave/doc/interpreter/Displaying-Images.html
for commands to display images. Hopefully with some manipulation it will work. This works for raw images, though there are specific decoders. Once you understand how the image is, you can write the equivalent C code.

Resources