Page 1 of 1

MagickResizeImage fails. How to get error details?

Posted: 2011-12-18T14:08:53-07:00
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 );

}

Re: MagickResizeImage fails. How to get error details?

Posted: 2011-12-18T14:42:47-07:00
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.

Re: MagickResizeImage fails. How to get error details?

Posted: 2011-12-18T17:56:03-07:00
by hiigara
Thank you! I fixed the problem.