last day (19 days later) » 

10:01 AM
0
A: Golang Converting Image magick object to []byte

jdiThis question is actually two questions, and @SirDarius answered one of them, by suggesting the use of GetImageBlob(). You can also use SetImageFormat() to change the image format before generating the blob. For the part about the crop, I am sure there are a bunch of ways to do this with ImageMa...

 
But here you are not taking use of aspect ratio. I have the requirement like let's say image is in 16:9 aspect ratio and then i need to convert it in nearest 4:3 aspect ratio. So, how do i it using above method
 
jdi
Oh you don't want a center crop then. You want a fit and pad
 
Currently, I am using mw.CropImage(uint(originalWidth), (uint(originalWidth / masterAspectRatio)), 0, 0). But it crops the image from origin and keep the width and height as mentioned. So, if let's say i want to change the aspect ratio from 16:9 to 4:3 then i want to crop the width from both the side and similarly if i want to change the aspect ration from 4:3 to 16:9 then i need to crop the height from both the side to get the image in desired aspect ratio .
So, how as i mentioned in the question in the .net it could be done like imgStream.Crop((int)originalWidth, ((int)(originalWidth / masterAspectRatio)), Gravity.Center. Similarly how do i do it in go that is my question
 
jdi
Out of curiosity have you even tried my suggestion or did you just look at it and assume it isn't what you want? because after yout comment, now it does sound like you want a proper center crop, which is what mine does
I resize it down to match a smaller target if necessary and then I crop it at the center
 
how do yo do that?
i am first cropping to the nearest smaller image and then resizing
 
jdi
10:08 AM
hello
in my example I first transform and then crop
cropping first makes no sense
resize to the smaller dimension, preserving aspect so that you have the closest size possible and then crop away the extra bits from sides or top and. bottom
I'm logging off for the night. but that code I shared was from a production thumbnail caching server that did exactly what I explained
 
 
4 hours later…
1:55 PM
But, how do you resize to your nearest smaller dimension of the desired aspect ratio. In your code what would be the value of w and h. Is it the original image width and height or something else. Again i am emphasizing i always crop the image to the NEAREST SMALLER dimension of desired ratio in case you missed that term
So, how is it different if i crop first and then resize or i resize first then crop it.
 
2:09 PM
By the way, why there is no function similar to .net which takes three parameters of width, height and gravity. Moreover, in imagick for go i couldn't find the boolean parameter of aspect ratio. Using which while resizing the image we can modify aspect ratio according to our requirement
 
 
3 hours later…
jdi
5:30 PM
first of all, there is nothing here that is specific to Go. Imagick is a thin wrapper around ImageMagick so we expose the ImageMagick api
my point about resizing first is... say your source is 2048x1556 and you want to output 640x360. my example would first resize it down to 640x486. This preserved aspect and fits the width. Now there is an overflow of height because the aspect ratio is different. So I perform a center crop to go from 640x486 to 640x360
 

  last day (19 days later) »