🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: chile.comp.programacion
Article #402

Re: Le pueden dar una miradita porfa ?

#402
From: Daniel Molina Wegener
Date: Thu, 26 Feb 2009 06:46
213 lines
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-----
Technical Details
Message-ID: <y_-dne-VR9CxpjvUnZ2dnUVZ_qDinZ2d@giganews.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news1.google.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail
References: <glsck2$rht$1@news.nivel5.cl>

Show Full Headers
Complete Article Headers
X-Google-Thread: 1593cb,aaefd102ac708d0c
X-Google-Attributes: gid1593cb,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news1.google.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Thu, 26 Feb 2009 00:48:12 -0600
From: Daniel Molina Wegener <dmw@coder.cl>
Subject: Re: Le pueden dar una miradita porfa ?
Newsgroups: chile.comp.programacion
Reply-To: dmw@coder.cl
Date: Thu, 26 Feb 2009 03:46:30 -0300
References: <glsck2$rht$1@news.nivel5.cl>
Organization: http://coder.cl/
User-Agent: KNode/0.10.9
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7Bit
Message-ID: <y_-dne-VR9CxpjvUnZ2dnUVZ_qDinZ2d@giganews.com>
Lines: 213
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-jpH/WLpp/ZEYIS0zhHjpeDWQvMn3ve5v9yo1FSkIHa0dgjxxhxDAZiEiZEVU+EmAWanpJueMdhvAG4s!wvu3Y5hnlxyOULVn/bSrJniEHD68QqSoQ9nVSiKuhq79lABM1qW5edFHr35osU5XcW73Q4uGRg==
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.39