Page 1 of 1

DrawSetDensity example

Posted: 2016-03-06T15:36:41-07:00
by Danack
Hi,

Please you could you either say or add to the documentation, what format the density string should take for the DrawSetDensity() function, and what it is used for?

cheers
Dan

Re: DrawSetDensity example

Posted: 2016-03-06T21:19:34-07:00
by snibgo
What API contains a DrawSetDensity() function? I can't find it in the Core or Wand APIs.

Re: DrawSetDensity example

Posted: 2016-03-06T23:14:25-07:00
by snibgo
Okay, I've found it in v7 drawing-wand.c.

draw.c function DrawBoundingRectangles() suggests the string should be two numbers separated by comma or "x".

Re: DrawSetDensity example

Posted: 2016-03-07T08:04:21-07:00
by Danack
It's also in ImageMagick 6 since at least 6.9.2-0

I've tried using it with numbers separated by either x or a comma. Trying to render the drawing wand into an image, using the example code below, gives an error "ThrowWandException 11 non-conforming drawing primitive definition `density' @ error/draw.c/DrawImage/3169"

For the record I'm just trying to add it to the PHP Imagick extension, so would like to be able to describe what it does for the manual, as well as be able to write a test for it.

Code: Select all


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wand/MagickWand.h>


void ThrowWandException(MagickWand *wand) {
    char *description; 
    ExceptionType severity; 
    description = MagickGetException(wand, &severity); 
    (void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description); 
    description=(char *) MagickRelinquishMemory(description); 
    exit(-1); 
}


PixelWand *makePixelWand(char *string) {

	PixelWand *pixel_wand;
	pixel_wand = NewPixelWand();

	if (PixelSetColor (pixel_wand, string) == MagickFalse) {
		printf("Failed to set color");
		exit(-1);
	}

	return pixel_wand;
}

int main(int argc,char **argv)
{
    DrawingWand *drawing_wand;
    MagickWand *magick_wand;
    PixelWand *background_color_wand;
    MagickBooleanType status;

    MagickWandGenesis();
    
    drawing_wand = NewDrawingWand();

    //DrawSetDensity(drawing_wand,"200x200");
    DrawSetDensity(drawing_wand,"200,200");

    magick_wand = NewMagickWand();
    background_color_wand = makePixelWand("red");
    MagickNewImage(magick_wand, 500, 500, background_color_wand);
    DrawRectangle(drawing_wand, 100, 100, 400, 400);

    status = MagickDrawImage(magick_wand, drawing_wand);
    if (status == MagickFalse) {
        ThrowWandException(magick_wand);
    }
    
    MagickWriteImages(magick_wand, "./output/setDensity.png", MagickTrue);

    MagickWandTerminus();
    return (0);
}


Re: DrawSetDensity example

Posted: 2016-03-07T08:58:23-07:00
by snibgo
Ah, that explains it. My v6 source is v6.9.0-0. As far as I can see (in v7 source), it is used only in draw.c DrawBoundingRectangles(), which "is only useful for developers debugging the rendering algorithm".

But a developer might comment.