I'm using golang and this (https://github.com/quirkey/magick) package to resizing images in my project. All images are in sRGB colorspace.
And all was great, until I needed to resize an image, that contains only black and white colors. After convertation, image became terrible. I thought that reason in colorspaces and playing with it, but it has not given a satisfactory result.
With
Code: Select all
identify converted.png
After internet-digging I found this case:
Code: Select all
identify -format "%[colorspace]"
And I found type option! http://www.imagemagick.org/script/comma ... s.php#type This is exactly what I needed. I used it with TrueColorMatte and saw that image is resized, looking good and still in sRGB.
And question: How I can use this option in my go code? I founded this method in MagickCore API: http://www.imagemagick.org/api/attribut ... tImageType and it looks like what I need, but it has no effect, image still Gray.
I wrote this code to test it:
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <magick/MagickCore.h>
MagickBooleanType CheckException(ExceptionInfo *exception)
{
register const ExceptionInfo
*p;
int haserr = 0;
assert(exception != (ExceptionInfo *) NULL);
assert(exception->signature == MagickSignature);
if (exception->exceptions == (void *) NULL)
return MagickFalse;
LockSemaphoreInfo(exception->semaphore);
ResetLinkedListIterator((LinkedListInfo *) exception->exceptions);
p=(const ExceptionInfo *) GetNextValueInLinkedList((LinkedListInfo *)
exception->exceptions);
while (p != (const ExceptionInfo *) NULL)
{
if ((p->severity >= WarningException) && (p->severity < ErrorException))
haserr = 1;
if ((p->severity >= ErrorException) && (p->severity < FatalErrorException))
haserr = 1;
if (p->severity >= FatalErrorException)
haserr = 1;
p=(const ExceptionInfo *) GetNextValueInLinkedList((LinkedListInfo *)
exception->exceptions);
}
UnlockSemaphoreInfo(exception->semaphore);
return haserr == 0 ? MagickFalse : MagickTrue;
}
int main() {
printf("Started\n");
// --- open img
ExceptionInfo *exception = AcquireExceptionInfo();
ImageInfo *info = AcquireImageInfo();
char* c_filename = "original.png";
(void) CopyMagickString(info->filename,c_filename,MaxTextExtent);
Image *image = ReadImage(info, exception);
MagickBooleanType failed = CheckException(exception);
if (failed == MagickTrue) {
DestroyImageInfo(info);
printf("All bad (open)\n");
// return nil, ErrorFromExceptionInfo(exception)
return 1;
}
DestroyExceptionInfo(exception);
// ---
// --- do resize
exception = AcquireExceptionInfo();
image = AdaptiveResizeImage(image, 100, 100, exception);
DestroyExceptionInfo(exception);
// ---
// -- do type
MagickBooleanType success = SetImageType(image, TrueColorMatteType);
if (success != MagickTrue) {
printf("All bad (set type)\n");
}
// ---
// --- save img
exception = AcquireExceptionInfo();
char* c_outpath = "converted.png";
CopyMagickString(info->filename,c_outpath,MaxTextExtent);
success = WriteImages(info, image, c_outpath, exception);
failed = CheckException(exception);
if (failed == MagickTrue) {
DestroyImageInfo(info);
printf("All bad (close f)\n");
// return nil, ErrorFromExceptionInfo(exception)
return 1;
}
if (success != MagickTrue) {
printf("All bad (close s)\n");
}
DestroyExceptionInfo(exception);
// ---
printf("All done!\n");
}
Am I doing something wrong?
PS I can write go wrapper to this C-function, but I need a working solution on C at least