gravity.cpp
Go to the documentation of this file.
// This may look like C code, but it is really -*- C++ -*-
//
// Copyright Bob Friesenhahn, 2000, 2001, 2003
//
// Copyright @ 2013 ImageMagick Studio LLC, a non-profit organization
// dedicated to making software imaging solutions freely available.
//
// Demo of text annotation with gravity. Produces an animation showing
// the effect of rotated text assize_t with various gravity specifications.
//
// After running demo program, run 'animate gravity_out.miff' if you
// are using X-Windows to see an animated result.
//
// Concept and algorithms lifted from PerlMagick demo script written
// by John Christy.
//
#include <Magick++.h>
#include <string>
#include <iostream>
#include <list>
using namespace std;
using namespace Magick;
int main( int /*argc*/, char ** argv)
{
// Initialize ImageMagick install location for Windows
InitializeMagick(*argv);
try {
string srcdir("");
if(getenv("SRCDIR") != 0)
srcdir = getenv("SRCDIR");
int x = 100;
int y = 100;
list<Image> animation;
Image base( Geometry(600,600), Color("white") );
base.depth(8);
base.strokeColor("#600");
base.fillColor(Color());
base.draw( DrawableLine( 300,100, 300,500 ) );
base.draw( DrawableLine( 100,300, 500,300 ) );
base.draw( DrawableRectangle( 100,100, 500,500 ) );
base.density( Point(72,72) );
base.strokeColor(Color());
base.fillColor("#600");
base.fontPointsize( 30 );
base.boxColor( "red" );
base.animationDelay( 20 );
base.compressType( RLECompression );
for ( int angle = 0; angle < 360; angle += 30 )
{
cout << "angle " << angle << endl;
Image pic = base;
pic.annotate( "NorthWest", Geometry(0,0,x,y), NorthWestGravity, angle );
pic.annotate( "North", Geometry(0,0,0,y), NorthGravity, angle );
pic.annotate( "NorthEast", Geometry(0,0,x,y), NorthEastGravity, angle );
pic.annotate( "East", Geometry(0,0,x,0), EastGravity, angle );
pic.annotate( "Center", Geometry(0,0,0,0), CenterGravity, angle );
pic.annotate( "SouthEast", Geometry(0,0,x,y), SouthEastGravity, angle );
pic.annotate( "South", Geometry(0,0,0,y), SouthGravity, angle );
pic.annotate( "SouthWest", Geometry(0,0,x,y), SouthWestGravity, angle );
pic.annotate( "West", Geometry(0,0,x,0), WestGravity, angle );
animation.push_back( pic );
}
cout << "Writing image \"gravity_out.miff\" ..." << endl;
writeImages( animation.begin(), animation.end(), "gravity_out.miff" );
// system( "animate gravity_out.miff" );
}
catch( exception &error_ )
{
cout << "Caught exception: " << error_.what() << endl;
return 1;
}
return 0;
}
Magick::DrawableRectangle
Definition: Drawable.h:1401
Magick::Color
class MagickPPExport Color
Definition: Color.h:18
Magick::Image::annotate
void annotate(const std::string &text_, const Geometry &location_)
Definition: Image.cpp:1858
Magick::Image::density
void density(const Point &density_)
Definition: Image.cpp:653
std
STL namespace.
Magick++.h
Magick::Image::strokeColor
void strokeColor(const Color &strokeColor_)
Definition: Image.cpp:1403
Magick::DrawableLine
Definition: Drawable.h:1121
Magick::Image::boxColor
void boxColor(const Color &boxColor_)
Definition: Image.cpp:457
Magick::Image::fontPointsize
void fontPointsize(const double pointSize_)
Definition: Image.cpp:874
Magick::Geometry
class MagickPPExport Geometry
Definition: Geometry.h:21
Magick::writeImages
void writeImages(InputIterator first_, InputIterator last_, const std::string &imageSpec_, bool adjoin_=true)
Definition: STL.h:2823
Magick::Image::fillColor
void fillColor(const Color &fillColor_)
Definition: Image.cpp:786
Magick::Image::draw
void draw(const Drawable &drawable_)
Definition: Image.cpp:2798
Magick::Image::animationDelay
void animationDelay(const size_t delay_)
Definition: Image.cpp:354
main
int main(int, char **argv)
Definition: gravity.cpp:27
Magick::Point
class MagickPPExport Point
Definition: Geometry.h:200
Magick
Definition: Blob.h:17
Magick::InitializeMagick
MagickPPExport void InitializeMagick(const char *path_)
Definition: Functions.cpp:45
Magick::Image::depth
void depth(const size_t depth_)
Definition: Image.cpp:693
Magick::Image
Definition: Image.h:55
Magick::Image::compressType
void compressType(const CompressionType compressType_)
Definition: Image.cpp:630