Thread View: chile.comp.programacion
4 messages
4 total messages
Started by Carlos G.P
Thu, 29 Jan 2009 13:57
Le pueden dar una miradita porfa ?
Author: 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;
}
Re: Le pueden dar una miradita porfa ?
Author: Marco A. Orellana O.
Date: Wed, 04 Feb 2009 20:49
Date: Wed, 04 Feb 2009 20:49
8 lines
1227 bytes
1227 bytes
Carlos G.P escribi�: > // watermarker 1.0 by Paul Blackburn (pawulb@gmail.com). > > [...] y? si incluyes el lib y el .h, seria buenisimo! Marco
Re: Le pueden dar una miradita porfa ?
Author: Knock_
Date: Wed, 18 Feb 2009 20:16
Date: Wed, 18 Feb 2009 20:16
149 lines
5180 bytes
5180 bytes
Carlos G.P wrote:
> // 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;
> }
y que quieres con esto ?, ya le ech� una mirada =)
Salu2,
Knock_
Re: Le pueden dar una miradita porfa ?
Author: Daniel Molina Wegener
Date: Thu, 26 Feb 2009 06:46
Date: Thu, 26 Feb 2009 06:46
213 lines
7512 bytes
7512 bytes
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
Carlos G.P <carlosgp@ladegoogle.com>
on Thursday 29 January 2009 10:57
wrote in chile.comp.programacion:
> // watermarker 1.0 by Paul Blackburn (pawulb@gmail.com).
>
>
> #include <pngwriter.h>
/* primer problema, se usa el prefijo "c" y se quita el .h
de los headers de C, p.e. <cstdlib>, <cstring>, etc. */
> #include <stdlib.h>
/* - no confundir <string> de C++ con <cstring> de C... */
> #include <string>
> #include <iostream>
> #include <fstream>
/* si declara que esta usando el namespace std, no necesita
agregarlo luego como std:: */
> using namespace std;
>
> int main(int argc, char * argv[])
> {
> if(argc != 4)
/* - esta demasiado en duro, usa una macro
#define LIMITE_ARGS 4, o algo similar...
- se usa std::endl en lugar de \n */
> {
> 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";
/* - se usa EXIT_SUCCESS o EXIT_FAILURE, no los parametros
en duro. */
> 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");
/* - no verifica la exitencia del archivo con
access(2) o stat(2) */
> image.readfromfile(filename.c_str());
>
> char * fn;
> fn = new char[1024];
/* - strcpy(3) es inseguro, se debe usar strncpy(3)
- no se limpia el buffer de fn antes de usarlo con memset(3) o
bzero(3) */
> 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++)
> {http://pngwriter.sourceforge.net/
> 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];
/* de nuevo strcpy(3)... */
> strcpy(fl, filename.c_str());
> newfilename = strtok (fl, "." );
/* strcat(3) es inseguro, se debe usar strncat(3) */
> 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;
> }
Me aburri... quiero dormir :S
Esto mismo se podria haber hecho en PHP5 con gd o en python
tambien... xD
Las rutinas de imagenes son de este paquete:
http://pngwriter.sourceforge.net/
Atte.
- --
.O. | Daniel Molina Wegener | FreeBSD & Linux
..O | dmw [at] coder [dot] cl | Open Standards
OOO | http://coder.cl/ | FOSS Developer
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (FreeBSD)
iQIcBAEBCgAGBQJJpjrGAAoJEHxqfq6Y4O5NpdoP/3bG762j2f7/VbJZIazpdVxN
mahNgxLGpIDMxbi1b1/QUDXdwk6K9VjKX4Wi52JkeOKVNnCO6n1LrCavmg9JXxWA
hq73TNOxaqd3r1zV11JlisCJqFgfF96cSaf1wjIp6RP2JUiNRMCwVxJb4bdM0dLY
NgZFT7kAJVtvNirGVPDLP9sVvStYN0WCCpMt1C4sa9h3iOCJ5P5Z3OOuyJP63fsI
vk0iRaw5rlDF5+5QBZZpEeoHRB3k0su442V+l2wmGiAxjaLjNDNQWNfvQYZEy2T+
8nTJKrLn+QXH+sTrldSKDYZLuyKMflAXTomaBozO6NZ1couwJdkUTKn6VD5QPhJw
pea0dxQIl64tEpQ6lIFMsvTr37W9A+Lz7AEz9DfR5CLWCvJ4kZ3xQgPLMaGjArwq
TW5+XVhNXvSsRerxIf9k7t2h4f5clzJpjLEvY7IGwlvp7N2plIp6Eww32UEzVanv
kEKeOHXM6n3VxcYlJXqWhSB8X0JdLz6lq4wFYyt+tfdRebCkd8xnawVyDnPjBcBp
vGR8BBvDceuDtk/3aaC41JOyovCgnh9+0kRcQnCgEiDkJ8nRWum+blrBzOWX/eCp
QimUOc9frQM3cJg67MC3fHnlAzRe7z83zgBv6D3uLBH8hYS2A5AAtKCcD0N3cFOP
BabDwgiCaADGqfdGEpNZ
=6ZOS
-----END PGP SIGNATURE-----
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads