Article View: chile.comp.programacion
Article #394Le pueden dar una miradita porfa ?
From: Carlos G.P
Date: Thu, 29 Jan 2009 13:57
Date: Thu, 29 Jan 2009 13:57
137 lines
4630 bytes
4630 bytes
// watermarker 1.0 by Paul Blackburn (pawulb@gmail.com).
#include <pngwriter.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char * argv[])
{
if(argc != 4)
{
std::cout << "Wrong number of args (" << argc - 1 << "). Usage: ";
std::cout << "watermarker <config file> <UTF8 string file>";
std::cout << "<png image file>\n";
std::cout << "UTF8 string file should be a plain text or";
std::cout << "UTF8-formatted text file containing the copyright string";
std::cout << "to be used. \nConfig file should be a text file containing,";
std::cout << "on separate lines, \n";
std::cout << " pos_x;\n pos_y\n font_size\n blend coef.\n";
std::cout << " fontfile\n";
exit(1);
}
// Get copyright string into a binary array.
char * copyrightfile = argv[2];
char * copyright;
long size;
ifstream file (copyrightfile, ios::in|ios::binary|ios::ate);
if (! file.is_open())
{
std::cout << "Error opening UTF8 text file."; exit (1);
}
size = file.tellg();
file.seekg (0, ios::beg);
copyright = new char [size];
file.read (copyright, size);
file.close();
// Load configuration parameters.
std::ifstream params (argv[1]);
if (! params.is_open())
{
std::cout << "Error opening config file"; exit (1);
}
string filename(argv[3]);
string fontfile;
int pos_x;
int pos_y ;
int font_size;
double angle;
double blend;
params >> pos_x;
params >> pos_y;
params >> font_size;
params >> blend;
params >> fontfile;
params.close();
// Create PNGwriter instance
pngwriter image(1,1,0,"caca.png");
image.readfromfile(filename.c_str());
char * fn;
fn = new char[1024];
strcpy( fn, fontfile.c_str());
double average;
int minx, miny, maxx, maxy;
average= 0.0;
angle = 1.57079633;
minx = image.getwidth() - pos_x;
maxx = image.getwidth();
maxy = pos_y + image.get_text_width_utf8(fn, font_size, copyright);
miny = pos_y;
// Calculate the average intensity of the image
// behind the text.
for(int xx=minx; xx <=maxx; xx++)
{
for(int yy=miny; yy <=maxy; yy++)
{
average = average + image.dread(xx,yy);
}
}
average = average/( (double)( (maxx-minx)*(maxy-miny) ));
std::cout << "Average image intensity in text area: " << average;
std::cout << ", Number of pixels taken: " << (maxx-minx)*(maxy-miny);
std::cout << ", text will be";
// Plot the text on the image.
if(average>0.5)
{
std::cout << " black." <<std::endl;
image.plot_text_utf8_blend( fn, font_size,
image.getwidth() - pos_x, pos_y, angle,
copyright,
blend,
0.0, 0.0, 0.0);
}
else
{
std::cout << " white." <<std::endl;
image.plot_text_utf8_blend( fn, font_size,
image.getwidth() - pos_x, pos_y, angle,
copyright,
blend,
1.0, 1.0, 1.0);
}
// Rename the file, add -wmk to the basename.
char * newfilename;
char fl[1024];
strcpy(fl, filename.c_str());
newfilename = strtok (fl, "." );
strcat(newfilename, "-wmk.png" );
image.pngwriter_rename(newfilename);
image.settext(filename.c_str(), "Paul Blackburn",
"Copyright 2006 Paul Blackburn, paulwb AT gmail.com, All Rights
Reserved.",
"Watermaked with PNGwriter plus a small program called watermarker.");
// Write the PNG image to disk.
image.close();
delete [] fn;
return 0;
}
Technical Details
Message-ID:
<glsck2$rht$1@news.nivel5.cl>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news.glorb.com!news2.glorb.com!news-xfer.nntp.sonic.net!news.kjsl.com!news.nivel5.cl!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 1593cb,aaefd102ac708d0c,start X-Google-Attributes: gid1593cb,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news.glorb.com!news2.glorb.com!news-xfer.nntp.sonic.net!news.kjsl.com!news.nivel5.cl!not-for-mail From: "Carlos G.P" <carlosgp@ladegoogle.com> Newsgroups: chile.comp.programacion Subject: Le pueden dar una miradita porfa ? Date: Thu, 29 Jan 2009 10:57:22 -0300 Organization: Varios Lines: 137 Message-ID: <glsck2$rht$1@news.nivel5.cl> NNTP-Posting-Host: pc-211-47-83-200.cm.vtr.net Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.nivel5.cl 1233237442 28221 200.83.47.211 (29 Jan 2009 13:57:22 GMT) X-Complaints-To: news@news.nivel5.cl NNTP-Posting-Date: Thu, 29 Jan 2009 13:57:22 +0000 (UTC) User-Agent: Thunderbird 2.0.0.19 (X11/20090105)