function imageapi_imagemagick_image_overlaytext_alpha(&$image, $text, $size = 12, $x = 0, $y = 0, $RGB, $fontfile = 'MgOpenModernaBold', $angle = 0) 
{

	if ( $angle <> 0 )
		$image->ops[] = " -rotate ".$angle." -pointsize ".$size." -fill rgb(".$RGB['red'].','.$RGB['green'].','.$RGB['blue'].") -draw \"text ".$x.",".$y." 'Hello'\" -rotate '.-($angle).";
	else 
		$image->ops[] = " -pointsize ".$size." -fill rgb(".$RGB['red'].','.$RGB['green'].','.$RGB['blue'].") -draw \"text ".$x.",".$y." 'Hello'\" ";
	return true ;
}
CommentFileSizeAuthor
#8 textactions.inc-imagemagick-6.7.x.patch800 bytesbgilhome
#6 359339.patch803 bytesfax8

Comments

erik seifert’s picture

Problems are only with the angle and positioning ( because i must rotate the whole image then write a text and rotae it back ).

bismigalis’s picture

Wow man, thanx, it's what I need right now!!!

I only wrapped rgb() in doblequote, otherwise it dont worked.

fax8’s picture

I'm currently using this:

function imageapi_imagemagick_image_overlaytext_alpha(&$image, $text, $size = 12, $x = 0, $y = 0, $RGB, $fontfile = 'MgOpenModernaBold', $angle = 0) {
  if($angle != 0) {
    $image->ops[] = " -rotate ".$angle." -pointsize ".$size." -fill rgb\(".$RGB['red'].','.$RGB['green'].','.$RGB['blue']."\) -draw \"text ". ($x + 50) .",".$y." '$text'\" -rotate '.-($angle).";
  }
  else {
    $image->ops[] = " -pointsize ".$size." -fill rgb\(".$RGB['red'].','.$RGB['green'].','.$RGB['blue']."\) -draw \"text ". ($x + 50) .",".$y." '$text'\" ";
  }
  return true ;
}

Place the above in textactions.inc.

Notice that I escaped with \ the ( and ), used $text instead of Hello and added + 50 to the $x value.. yes.. this is very hacky but that's what was needed to place the text where I needed it to be.

Hope this helps someone,

Fabio Varesano

2ndmile’s picture

@fax8 - Thanks for this. I needed to use ImageMagick for the PDF_to_ImageField module so this came in handy. I did get the following error when trying to use an angle.

ImageMagick reported an error: sh: -c: line 0: unexpected EOF while looking for matching `'' sh: -c: line 1: syntax error: unexpected end of file

But for this project using the angle is not a big deal so I emptied the field and it worked as expected.

Andrey Zakharov’s picture

With support of rotating.
Rotates relative to bottom left point of text box.

/**
 * Place text on an image.
 *
 * @ingroup imageapi
 */
function imageapi_imagemagick_image_overlaytext_alpha(&$image, $text, $size = 12, $x = 0, $y = 0, $RGB = 'black', $fontfile = 'MgOpenModernaBold', $angle = 0) {
    $alpha = ($RGB['alpha'] / 127) + 1;
    $color = 'rgb(' . $RGB['red']. ', ' . $RGB['green'] . ', ' . $RGB['blue'] . ', '. $alpha . ')';

    $action .= " -font \"$fontfile\" -pointsize \"$size\" -fill \"$color\" -draw 'translate $x,$y rotate $angle text 0,0 \"$text\"'";

    $image->ops[] = $action;
    
    return TRUE;
}
fax8’s picture

StatusFileSize
new803 bytes

Converted Andrey Zakharov code into a proper patch. Tested with 6.x-1.8.

Now, can we have some maintainer attention? Thanks.

fax8’s picture

Category: support » feature
bgilhome’s picture

StatusFileSize
new800 bytes

Not sure if it's a ImageMagick 6.7.x change but the patch in #6 didn't apply opacity properly - here's an updated patch.

ryan_courtnage’s picture

Component: Text Actions Module » Code
Issue summary: View changes

#6 works with ImageMagick-6.5.4.7-6.el6_2.x86_64. (#8 doesn't)

fietserwin’s picture

Status: Needs review » Closed (won't fix)

D6 EOL. This module's D6 issues already haven't received any attention for over a year. Closing them all unconditionally now.