PDA

View Full Version : Addon "Add text"


eon
11-18-2005, 11:16 AM
I'am working on a addon for a schoolproject. I choose to make an addon for Pixelpost because I use it for my self (http://www.northing.nl), the flexibility of the program and the beautifull code.

My addon gives the user the chance to add text in stand of photo's in Pixelpost, like a blog. When you write text my addon makes a picture of the text and after that you can generate a thumbnail. It is a function that I miss in Pixelpost.

To create the thumbnail I wrote a function called "textoimage".
function texttoimage ($title, $text, $dir, $file, $bg_color, $title_color, $text_color, $font_height_text, $font_height_title, $image_h, $image_w , $maxtextwidth, $x_pos_text, $y_pos_text, $x_pos_title, $y_pos_title, $fonttype_title, $fonttype_text, $fontangle_title, $fontangle_text){
//create new image
$img_handle = imagecreate ($image_w, $image_h) or die ("Cannot Create image");

//set colors
list($bg_r,$bg_g,$bg_b)= split(",",$bg_color);
list($title_r,$title_g,$title_b)= split(",",$title_color);
list($text_r,$text_g,$text_b)= split(",",$text_color);
$background_color = imagecolorallocate ($img_handle, $bg_r, $bg_g, $bg_b);
$title_color = imagecolorallocate ($img_handle, $title_r, $title_g, $title_b);
$text_color = imagecolorallocate ($img_handle, $text_r, $text_g, $text_b);

//place text
$fontwidth = imagefontwidth($font_height_text);
$fontheight = imagefontheight($font_height_text);

//split-up the text in rows
if ($maxtextwidth != NULL) {
$maxcharsperline = floor($maxtextwidth / $fontwidth);
$text = wordwrap($text, $maxcharsperline, "\n", 1);
}

//insert text in image
$lines = explode("\n", $text);
imagettftext ($img_handle, $font_height_text, $fontangle_text, $x_pos_text, $y_pos_text, $text_color, $fonttype_text, $text);

//insert title in image
imagettftext ($img_handle, $font_height_title, $fontangle_title, $x_pos_title, $y_pos_title, $title_color, $fonttype_title, $title);

//save the image (Leave the string, woman and childeren first!!)
imagejpeg ($img_handle,$dir.$file,100);

//remove the image out the memory
imagedestroy($img_handle);
}

Screenshot 1, this is a screenshot of the image that is generated and you can select the croparea.
http://tweakers.net/ext/f/39f86e40693a31ca948082c11661beaf/full.jpg

Screenshot 2, this is a screenshot of how it is looklike when your text is a thumbnail.
http://tweakers.net/ext/f/890b29113960a5630735d345ce40b4af/full.jpg

So far I can make a thumbnail and fill the database with the correct data. But there are still thing I have to do.

TODO:
- Show the text on the right way on the frontsite
- Edit and delete the text.
- Write a correct installation.

The only problem is that I hack the Pixelpost so far that you can't speak anymore of an addon. For exmple I use the "New Image"-code to make my "New Text"-code. When I put the code in my addon, then it is not working. It has to stand in the index.php of the admin.
I can use some advise about this subject.

If there is any questions please ask. My story could be a little bit confusing because yesterday I had a party and now I have a little hangover. :rolleyes:

Because my bad condition I just see that I put the thread in "Bugs" instand of "Addons". :rolleyes: Moderator, can you correct this or do I have to make a new thread?

raminia
11-18-2005, 12:02 PM
no bug here.

eon
11-18-2005, 01:49 PM
no bug here.

Idd, this thread has to be moved to Addons.