/*
      _______                          .__ .__   .__   .__                 
      \      \    ____   __ __ _______ |__||  |  |  |  |__|  ____    ____  
      /   |   \ _/ __ \ |  |  \\_  __ \|  ||  |  |  |  |  | /  _ \  /    \ 
     /    |    \\  ___/ |  |  / |  | \/|  ||  |__|  |__|  |(  <_> )|   |  \
     \____|__  / \___  >|____/  |__|   |__||____/|____/|__| \____/ |___|  /
    =========\/======\/=================================================\/==
  v0.01 04/JUL/2007 (C) Copyright 2007-2007 Scott D. Yelich SOME RIGHTS RESERVED
 .,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.-*~'`^`'~*-,._.,-*~'`^`'~*-,. 


  LICENSE:  Creative Commons Attribution 3.0 License.
  SEE:      http://creativecommons.org/licenses/by/3.0/


  Sun Jul 29 21:33:38 EDT 2007, v0.02 sdy

  This is a *very* simple program written to do a web page
  hit counter using sqlite3.

*/

//  LDFLAGS= -lmagick -lpng -lz -ljpeg -lfreetype -lm

//  C++

#include <iostream>
#include <fstream>

//  LOCAL

#include "Magickx.h"


Magickx::Magickx()
{
  image_depth=8;
  stroke_width=1;
  angle=0;
  point_size=12;
  stroke_color="black";
  fill_color="black";

  std::string f("default.ttf");
  set_font(f);
}

Magickx::~Magickx()
{
}

Magickx &
Magickx::make_img( std::string & text )
{

  int text_length = text.size();

  int size = point_size*text_length+point_size*2;

  try {

    Magick::Image image(Magick::Geometry(size,size), Magick::Color("transparent"));

    //    image.antiAlias(true); //  true by default.
    image.strokeColor(stroke_color);
    image.fillColor(fill_color);
    image.strokeWidth(stroke_width);
    image.fontPointsize(point_size);
    image.font(font.c_str());

    image.annotate(text, Magick::Geometry(0,0), Magick::CenterGravity, angle);
    image.trim();

    text="Neurillion";
    image.comment(text);
    image.depth(image_depth);

    //image.matte(false);
    image.write("png:-");

  }
  catch( std::exception &err )
  {
    //  cout << "Caught exception: " << err.what() << endl;
    //  display a transparent gif here?
  }

  return *this;

}

Magickx &
Magickx::set_font ( std::string & font_name )
{
  font = "/www/neurillion/p/33/fonts/ttf/";
  font.append(font_name);
  std::ifstream file(font.c_str());
  if ( ! file ) {
    font = "/www/neurillion/p/33/fonts/ttf/default.ttf";
  }
  return *this;
}




