MagickResizeImage fails. How to get error details?

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
Post Reply
hiigara
Posts: 4
Joined: 2011-12-17T13:59:09-07:00
Authentication code: 8675308

MagickResizeImage fails. How to get error details?

Post by hiigara »

Hello. I am a magickwand beginner.
This code fails in MagickResizeImage. The message "MagickResizeImage failed!" is printed in my log.
I would like to get an error detail on why MagickResizeImage is failing. How can I do that?
Thanks.

Code: Select all

if( MagickReadImage( g_Magickwand, _fb ) == MagickTrue ){

	char* _Format = MagickGetImageFormat( g_Magickwand );
	Formatbuffer _Original( 0 );
	
	if( _Format != NULL ){
	
		xx( 9, "MagickGetImageFormat %s.", _Format );
		_Original( "photo/%u.%s", _Photoid, _Format );
		
	}else{
	
		_Original( "photo/%u", _Photoid );
	}
	
	MagickRelinquishMemory(_Format);
	rename( _fb, _Original );
	int _Width = MagickGetImageWidth(g_Magickwand);
	int _Height = MagickGetImageHeight(g_Magickwand);

	if( _Width <= Thumbnailsize && _Height <= Thumbnailsize ){
	
		return;
	}
	
	int _Newwidth, _Newheight;
	
	if( _Width >= _Height ){
	
		_Newwidth = Thumbnailsize ;
		float _Ratio = _Newwidth / _Width ;
    _Newheight = _Height * _Ratio;
		
	}else{
	
		_Newheight = Thumbnailsize ;
		float _Ratio = _Newheight / _Height ;
    _Newwidth = _Width * _Ratio;
	}

	MagickBooleanType _ret = MagickResizeImage( g_Magickwand, _Newwidth,
		_Newheight, LanczosFilter, 1.0 );
		
	if( _ret == MagickTrue ){

		xx( 9, "New size %dx%d.", _Newwidth, _Newheight );
		
	}else{
	
		xx( 1, "MagickResizeImage failed!" );
	}
	
	MagickSetImageCompressionQuality( g_Magickwand, 95 );
	Formatbuffer _Convertedimage( 0 );
	_Convertedimage( "photo/%u_tn.jpg", _Photoid );
	MagickWriteImage( g_Magickwand, _Convertedimage );

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

Re: MagickResizeImage fails. How to get error details?

Post by magick »

If a method fails it returns an exception. See http://www.imagemagick.org/script/magick-wand.php. The example illustrates a way get the exception reason to determine why the method failed.
hiigara
Posts: 4
Joined: 2011-12-17T13:59:09-07:00
Authentication code: 8675308

Re: MagickResizeImage fails. How to get error details?

Post by hiigara »

Thank you! I fixed the problem.
Post Reply