00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "openLogger.h"
00012 #include <map>
00013 #include <string>
00014 #include <sstream>
00015 #include <fstream>
00016 #include <iostream>
00017 #include <iomanip>
00018 #include <Magick++.h>
00019 #include "ocString.h"
00020 #include "ocFileSys.h"
00021
00022 class rev_date_ocDirEntry
00023 {
00024 public:
00025 bool operator ( ) ( const ocDirEntry & d1, const ocDirEntry & d2 )
00026 {
00027 return d1.last_mod > d2.last_mod;
00028 }
00029 };
00030 rev_date_ocDirEntry rev_dates;
00031
00032 using namespace Magick;
00033 class imageConditioner
00034 {
00035 private:
00036 string m_imageBase;
00037 string m_imageDir;
00038 string m_thumbDir;
00039
00040
00041 int boundX;
00042 int boundY;
00043 int FSboundX;
00044 int FSboundY;
00045
00046
00047 FilterTypes filter;
00048 unsigned int quality;
00049
00050 public:
00051
00052
00053 imageConditioner()
00054 :m_imageBase("./")
00055 ,boundX(120),boundY(120)
00056 ,FSboundX(510),FSboundY(510)
00057 ,filter(LanczosFilter),quality(75)
00058 {
00059 m_imageDir = "./images";
00060 m_thumbDir = "./small_images";
00061 }
00062 virtual ~imageConditioner(){;}
00063
00064 void ImagesDelete( string imgDelete )
00065 {
00066 string delPath = m_imageDir;
00067 delPath +="/";
00068 delPath += imgDelete;
00069 string delThumbPath = m_thumbDir;
00070 delThumbPath +="/";
00071 delThumbPath +=imgDelete;
00072 ocFileSys fs;
00073 writelog2( "Deleting ", delPath );
00074
00075 if( !fs.remove(delPath) )
00076 {
00077 cout << fs.check();
00078 cout << " image path: " << delPath << endl;
00079 }
00080
00081 if( !fs.remove(delThumbPath) )
00082 {
00083 cout << fs.check();
00084 cout << " thumb path: " << delThumbPath << endl;
00085 }
00086 }
00087 void setArgs( int argcount, char ** args )
00088 {
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109 }
00110 bool isFile( ocString candidate )
00111 {
00112 bool bret;
00113 bret = candidate.regExMatch("[A-Z][a-z][0-9]*\x2e[bmpnjpgtif,BMPNJPGTIF]*");
00114 if( bret ) bret = ! candidate.regExMatch("imageBatch");
00115 return bret;
00116 }
00117
00118 void imageProcess(void)
00119 {
00120
00121 cout << "Image Processing "<< m_imageBase << endl;
00122
00123
00124 ocFileSys fs;
00125 writelog2("Scanning image Directory",m_thumbDir);
00126 if( fs.openDir(m_imageBase) )
00127 {
00128 ocDirectory & entries = fs.getDirectoryEntries();
00129
00130 sort( entries.begin(),
00131 entries.end(),
00132 rev_dates );
00133
00134
00135 int iEntries = entries.size();
00136 int iMax = 0;
00137 bool filesFound = false;
00138 bool showAll = true;
00139
00140 for( int iRow = 0;
00141 iRow < iEntries ;
00142 ++iRow )
00143 {
00144 if( isFile(entries[iRow].name) )
00145 {
00146 cout << endl << " Processing : " << entries[iRow].name << endl;
00147 makeThumb(entries[iRow].name);
00148 scaleSource(entries[iRow].name);
00149 }
00150 }
00151 }
00152
00153 }
00154 string imageDir( void )
00155 {
00156 return m_imageDir;
00157 }
00158 string imageBase( void )
00159 {
00160 return m_imageBase;
00161 }
00162
00163 void makeThumb( string imgEntry )
00164 {
00165 string m_fileUploaded = imgEntry;
00166 string imgPath = m_imageBase;
00167 imgPath +="/";
00168 imgPath += m_fileUploaded;
00169 string smlPath = m_thumbDir;
00170 smlPath +="/";
00171 smlPath += m_fileUploaded;
00172 try
00173 {
00174 Image image;
00175
00176 image.read(imgPath);
00177
00178 Geometry geom( boundX, boundY );
00179
00180 geom.greater(true);
00181
00182 geom.aspect(false);
00183
00184
00185 image.filterType(filter);
00186 image.quality(quality);
00187
00188
00189 image.scale(geom);
00190
00191 image.write(smlPath);
00192 }
00193 catch( Exception &error_ )
00194 {
00195 cout << "Error creating thumbnail - Exception caught: " << error_.what() << endl;
00196 }
00197 }
00198
00199 void scaleSource( string imgEntry )
00200 {
00201 string m_fileUploaded = imgEntry;
00202 if (m_fileUploaded.length())
00203 {
00204 string imgBasePath = m_imageBase;
00205 string imgPath = m_imageDir;
00206 imgPath +="/";
00207 imgPath += m_fileUploaded;
00208 imgBasePath += m_fileUploaded;
00209
00210 try
00211 {
00212 Image image;
00213
00214 image.read(imgBasePath);
00215
00216 Geometry geom( FSboundX, FSboundY );
00217
00218 geom.greater(true);
00219
00220 geom.aspect(false);
00221
00222
00223 image.filterType(filter);
00224 image.quality(quality);
00225
00226
00227 image.scale(geom);
00228
00229 image.write(imgPath);
00230 }
00231 catch( Exception &error_ )
00232 {
00233 cout << "Error sizing Full Scale Image - Exception caught: " << error_.what() << endl;
00234 }
00235 }
00236 }
00237 };
00238
00239 int main( int argcount, char ** args )
00240 {
00241
00242 imageConditioner picker;
00243 picker.imageProcess();
00244
00245 return 0;
00246 }
00247
00248