Image does not contain a geometry

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
Post Reply
peter01242
Posts: 17
Joined: 2016-06-22T11:32:57-07:00
Authentication code: 1151

Image does not contain a geometry

Post by peter01242 »

I have created a barcode using the following code:

Code: Select all

	Magick::Image Im(Magick::Geometry(600, 150), Magick::Color("white"));
	Im.colorSpace(Magick::GRAYColorspace);
	Im.font("CODE3X");
	Im.fontPointsize(48.0);
	Im.draw(Magick::DrawableText(20, 80, "*Barcode Test*"));
I want to position this at the bottom of another image (target) where (0,0) is the TLC using:

Code: Select all

	size_t nHPos = target.geometry().height() - Im.geometry().height();
The line above generates the exception that is the subject of this post relating to the barcode (Im).
Why does the barcode image not have a geometry that I can access?
Any suggestions?

Pete Young
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Image does not contain a geometry

Post by fmw42 »

It might help if you provide your IM version and platform and your resulting image.
peter01242
Posts: 17
Joined: 2016-06-22T11:32:57-07:00
Authentication code: 1151

Re: Image does not contain a geometry

Post by peter01242 »

I am using ImageMagick-7.0.2-Q8 on Windows 10 64-bit using VS2013 Pro (Version 12.0.40629.00 Update 5)
With the original code fragment I posted there is no final image as the exception was thrown and the image was not written to disk.

Here is the code that generates the barcode and writes it to disk:

Code: Select all

	// Read the image (quietly ignore any warnings, but not errors.)
	Magick::Image Im(Magick::Geometry(BARCODE_WIDTH, BARCODE_HEIGHT), Magick::Color("white"));
	Im.colorSpace(Magick::GRAYColorspace);
	Im.font("CODE3X");
	Im.fontPointsize(48.0);
	Im.draw(Magick::DrawableText(20, 80, "*Barcode Test*"));
	Im.magick("PNG");
	Im.write("barcode.png");
Here is a link to the barcode image that the previous code fragment generates:
https://www.dropbox.com/sh/sb7ma8mh5552 ... L3uDa?dl=0

Here is a link to the image.tif file used below:
https://www.dropbox.com/s/3hu28uo4hd7hy ... e.tif?dl=0

As an interesting side note, I also tried the following:

Code: Select all

	Magick::InitializeMagick(GetApplicationFolder().GetBuffer(0));
	try {
		Magick::Image target;
		target.quiet(true);
		target.read("image.tif");

		Magick::Geometry geom = target.geometry();
		size_t nHeightPixels = geom.height();
	}
	catch(Magick::Exception &error_) {
		printf("Barcode() failed. %s.\r\n", error_.what());
	}
The Geometry object returned from target.geometry() is empty (all fields set to zero or false), which is a little odd. I would have expected IM to have filled in at least some of these fields when it read the file and, given that this appears to be how you determine the size of the image you have read in, I find it a little worrying that no else seems to be having this problem.
peter01242
Posts: 17
Joined: 2016-06-22T11:32:57-07:00
Authentication code: 1151

Re: Image does not contain a geometry

Post by peter01242 »

After doing some more reading and head-scratching I decided to try rows() and columns() which appear to return the values that I require.
Having the Geometry object filled in after the read would be a nice feature addition as it does seem like a logical place to go looking for those details.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Image does not contain a geometry

Post by snibgo »

I don't use Magick++, but the documentation http://www.imagemagick.org/Magick++/Image++.html describes the image attributes:
coumns: Image width

rows: The number of pixel rows in the image

geometry: Preferred size of the image when encoding.
From that, if you want the width and height of an image, the relevant attributes seem clear.
snibgo's IM pages: im.snibgo.com
Post Reply