00001
00002
00003
00004
00005
00006
00007
00008 #ifndef IMAGEPROCESSOR_HPP
00009 #define IMAGEPROCESSOR_HPP
00010
00011
00012
00013 #include "openLogger.h"
00014 #include <map>
00015 #include <vector>
00016 #include <string>
00017 #include <sstream>
00018 #include <fstream>
00019 #include <iostream>
00020 #include <iomanip>
00021 #include <Magick++.h>
00022 #include "ocString.h"
00023 #include "ocFileSys.h"
00024
00025 class textAnnotation
00026 {
00027 public:
00028 string text;
00029 string color;
00030 string background;
00031 string fontFaceName;
00032 double pointSize;
00033 int width;
00034 int height;
00035 int posX;
00036 int posY;
00037 textAnnotation()
00038 :text("default"),color("#000070"),background("#ffffff"),fontFaceName("@VeraMono.ttf"),
00039 pointSize(10.0),width(200),height(10),posX(0),posY(0)
00040 {
00041 }
00042
00043
00044 textAnnotation(string text,string color,string background,string fontFaceName,
00045 double pointSize, int width, int height, int posX, int posY )
00046 :text(text),color(color),background(background),fontFaceName(fontFaceName),
00047 pointSize(pointSize),width(width),height(height),posX(posX),posY(posY)
00048 {
00049 }
00050
00051 textAnnotation & operator = ( textAnnotation & that )
00052 {
00053 this->text=that.text;
00054 this->color=that.color;
00055 this->background=that.background;
00056 this->fontFaceName=that.fontFaceName;
00057 this->pointSize=that.pointSize;
00058 this->width=that.width;
00059 this->height=that.height;
00060 this->posX=that.posX;
00061 this->posY=that.posY;
00062 return *this;
00063 }
00064 ~textAnnotation(){;}
00065
00066 };
00067
00068 typedef vector <textAnnotation> textAnnotations;
00069
00070 using namespace Magick;
00071 class imageProcessor
00072 {
00073 private:
00074 string m_imageBase;
00075 string m_imageDir;
00076 string m_proofDir;
00077
00078
00079
00080
00081 FilterTypes filter;
00082 unsigned int quality;
00083
00084 public:
00085
00086
00087 imageProcessor()
00088 :m_imageBase("./")
00089 ,filter(LanczosFilter),quality(75)
00090 {
00091 m_imageDir = "images";
00092 m_proofDir = "proofs";
00093 }
00094 virtual ~imageProcessor(){;}
00095
00096
00097
00098 bool isFile( ocString candidate )
00099 {
00100 bool bret;
00101 bret = candidate.regExMatch("[A-Z,a-z,0-9]*\x2e[bmpnjpgtif,BMPNJPGTIF]*");
00102 return bret;
00103 }
00104
00105 void imageProcess(string imageName, string session, textAnnotations annotations )
00106 {
00107
00108 cout << "Image Processing "<< m_imageBase << endl;
00109
00110
00111 if( isFile(imageName) )
00112 {
00113
00114 cout << endl << " Processing : " << imageName << endl;
00115 makeProof(imageName,session,annotations);
00116 }
00117
00118 }
00119
00120 string imageDir( void )
00121 {
00122 return m_imageDir;
00123 }
00124 string imageBase( void )
00125 {
00126 return m_imageBase;
00127 }
00128 string proofDir( void )
00129 {
00130 return m_proofDir;
00131 }
00132
00133 void imageDir( string inDir )
00134 {
00135 m_imageDir = inDir;
00136 }
00137 void imageBase( string inDir )
00138 {
00139 m_imageBase = inDir;
00140 }
00141 void proofDir( string inDir )
00142 {
00143 m_proofDir = inDir;
00144 }
00145 Image * makeAnnot( string text, int width, int height, string font, string bg , string clr, double pSize )
00146 {
00147
00148 Image * my_image = new Image( Geometry(width,height), Color(bg));
00149 my_image->strokeColor( Color(clr) );
00150 my_image->fillColor( Color(clr) );
00151 my_image->font(font);
00152 my_image->fontPointsize ( pSize );
00153 my_image->annotate( text, CenterGravity );
00154 return my_image;
00155 }
00156 void makeProof( string & imgEntry, string session, textAnnotations annotations )
00157 {
00158 if (imgEntry.length())
00159 {
00160 string imgProof = m_imageBase;
00161 string imgPath = m_imageBase;
00162 imgPath += m_imageDir;
00163 imgProof += m_proofDir;
00164 imgPath +="/";
00165 imgProof +="/";
00166 imgPath += imgEntry;
00167 imgProof += session + "." + imgEntry;
00168 cout << endl << " imgPath " << imgPath << " to imgProof " << imgProof << endl;
00169 try
00170 {
00171 Image image;
00172
00173 image.read(imgPath);
00174
00175
00176
00177 for( textAnnotations::iterator pos=annotations.begin(); pos != annotations.end(); pos++ )
00178 {
00179 textAnnotation ta = *pos;
00180
00181 Image * pImg = makeAnnot( ta.text, ta.width, ta.height,
00182
00183 ta.fontFaceName, ta.background, ta.color, ta.pointSize );
00184 image.composite( *pImg, ta.posX, ta.posY, OverCompositeOp );
00185 delete pImg;
00186 }
00187
00188 image.write(imgProof);
00189
00190
00191
00192
00193
00194 }
00195 catch( Exception &error_ )
00196 {
00197 cout << "Error Imagineering - Exception caught: " << error_.what() << endl;
00198 }
00199 }
00200 }
00201 };
00202 #endif
00203
00204 #ifdef IN_T2_TESTHARNESS
00205
00206
00207
00208
00209
00210
00211 cout << "Unit testing imageProcessor..." << endl;
00212 textAnnotations txtAnnots;
00213
00214
00215 txtAnnots.push_back(textAnnotation("Text To Add", "#ffffff","#000000","@VeraMono.ttf", 25, 230, 40, 10, 140 ));
00216
00217 txtAnnots.push_back(textAnnotation("read small print","#000000","#892034","@VeraMono.ttf", 10, 230, 12, 10, 5 ));
00218
00219 imageProcessor processor;
00220 processor.imageBase("/home/customlogomats/development/web/customlogomats/");
00221 processor.imageProcess("051303-JP.gif", "123AA43EE98");
00222
00223 #endif
00224
00225
00226