simples of questions

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
jamesb

simples of questions

Post by jamesb »

How do I create a new image, not from a file, using Magick Core? It needs to be 50k x 50k. I then need to set the pixels, in blocks of 16x16, and save the file. I have searched this forum, and the website, and not found anything that involves creating an image from scratch - only loading images and modifying them. Be grateful for some simple example code. Thanks.
James
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: simples of questions

Post by anthony »

Create an image with...

Code: Select all

  convert  -size 50000x50000 xc:black   save_image.png
to also set teh top left 16x16 area to red do...

Code: Select all

  convert  -size 50000x50000 xc:black   \
               -draw 'fill red -rectangle 0,0 15,15' \
               save_image.png
However if ALL 16x16 blocks are solid colors. a better way may be to create your image as a single pixel, and -scale it by 1600%

for example generating a 160x160 image with just the top left corner red
can be create dby creating a 10x10 pixel image with just one pixel red!

create a TXT image file (See http://www.imagemagick.org/Usage/files/#txt )
and call it "pixel_image.txt"
# ImageMagick pixel enumeration: 10,10,255,rgb
0,0: (255,0,0)
Now scale it

Code: Select all

  convert pixel_image.txt -scale 1600%  save_image.png
There are hundreds of ways of generating images.
See more in IM Examples, Canvases
http://www.imagemagick.org/Usage/canvas/
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
jamesb

Re: simples of questions

Post by jamesb »

I meant the C Magick Core interface. I just found the Architecture page and read that. What's missing is how to specify what format to save the file in, or rather, what specific version of the format. I want to save 64bit PNG, (RGBA 16bpc).

Thanks
Jamie
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: simples of questions

Post by magick »

To create a 50k x 50k image canvas use these MagickCore API calls:

Code: Select all

  Image *image = AcquireImage( image_info );
  if (SetImageExtent( image, 50*1024, 50*1024 ) == MagickFalse )
    perror( "somethings wrong" );
jamesb

Re: simples of questions

Post by jamesb »

How to specify saving 16bpc PNG vs 8bpc? Or float TIFF vs 8bpc TIFF? Or RGBA vs RGB?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: simples of questions

Post by magick »

Use SetImageDepth() to specify the image depth:
  • SetImageDepth( image, 8 );
To produce float TIFF images, try:
  • SetImageProperty( image, "quantum:format", "floating-point");
For RGBA images, use:
  • SetImageAlphaChannel( image, ActivateAlphaChannel );
Post Reply