Hallo Dave,
vielen Dank für das Addon. Super Sache!
Hatte bisher immer nur eine halbgare selbst gestrickte Sache als Modul eingesetzt ...
Eines ist mir aufgefallen, bei kleinen Schriftgrößen (<12) sieht die Glättung der Schrift ziemlich bescheiden aus ... ! Ist das nur bei so?!?
Eine mögliche Vorgehensweise um dieses Problem zu lösen (und eine gescheites Antialising zu erreichen) ist ja bei derartigen Skripts alle größenrelevanten Werte (Schriftgröße etc.) vorab z.B. um den Faktor 4 zu vergrößern und am Ende der Erstellung der Bildschrift das ganze wieder runter zu rechnen.
Ich habe mal etwas in der Art dilettantisch eingebaut, bei mir funzt es soweit gut ... allerdings kenne ich dein Skript nicht so gut, um zu wissen ob das auf diese Art und Weise geht (es ist aber so gut aufgebaut das der Einbau sehr gut ging ; )
Grüße
Robert
ps. die Stellen wo ich den Code ergänzt/verändert habe sind mit ANTIALIASING gekennzeichnet und es dreht sich nur um die Funktion generate()
Code: Alles auswählen
unction generate() {
global $REX;
$width = 0;
$height = 0;
$offset_x = 0;
$offset_y = 0;
$bounds = array();
$image = "";
// --- ANTIALIASING (new values for settings) ---
$antialiasing = 4;
$size_X = $this->setting('size') * $antialiasing;
$spacing_X = $this->setting('spacing') * $antialiasing;
// ---
###############################################################
## determine font height.
$bounds = ImageTTFBBox($size_X, 0, $this->setting('fontpath').$this->setting('font'), "W"); // ANTIALIASING: $this->setting('size') >>> $size_X
$font_height = abs($bounds[7]-$bounds[1]);
$bounds = ImageTTFBBox($size_X, 0, $this->setting('fontpath').$this->setting('font'), $this->setting('text')); // ANTIALIASING: $this->setting('size') >>> $size_X
$width = abs($bounds[4]-$bounds[6]);
$height = abs($bounds[7]-$bounds[1]);
$offset_y = $font_height;
$offset_x = 0;
###############################################################
## Deal with multiple lines
$spacing = floatVal($spacing_X); // ANTIALIASING: $this->setting('spacing') >>> $spacing_X
if ($spacing == 0 ) {
$spacing = 1.4;
}
$x = $offset_x+20;
$y = $offset_y+20;
$lines=explode("\n",$this->setting('text'));
for($i=0; $i< count($lines); $i++)
{ $newY=$y+($i * $size_X * $spacing); // ANTIALIASING: $this->setting('size') >>> $size_X
}
$newHeight = $newY + $font_height;
###############################################################
## Create Alpha Channel
$image = ImageCreateTrueColor($width+41,$newHeight+41);
ImageSaveAlpha($image, true);
ImageAlphaBlending($image, false);
$bg = ImageColorAllocateAlpha($image, 220, 220, 220, 127);
$bg2 = $bg;
ImageFill($image, 0, 0, $bg);
$fg = $this->setting('color');
$foreground = ImageColorAllocateAlpha($image, $fg[0], $fg[1], $fg[2], 0);
###############################################################
## Render all lines
$newY = 0;
for($i=0; $i< count($lines); $i++)
{ $newY=$y+($i * $size_X * $spacing); // ANTIALIASING: $this->setting('size') >>> $size_X
ImageTTFText($image, $size_X, 0, $x, $newY, $foreground, $this->setting('fontpath').$this->setting('font'), $lines[$i]); // ANTIALIASING: $this->setting('size') >>> $size_X
}
###############################################################
## Rotation
$angle = $this->setting('rotateX');
if ($angle>0) {
$magic = new a561_magic;
$image = $magic->rotate($image,$angle);
$bg2 = imagecolorat($image, 5, 5);
}
###############################################################
## Auto-Crop
$p = array_fill(0, 4, 0);
// Get the image width and height.
$imw = imagesx($image);
$imh = imagesy($image);
// Set the X variables.
$xmin = $imw;
$xmax = 0;
// Start scanning for the edges.
for ($iy=0; $iy<$imh; $iy++){
$first = true;
for ($ix=0; $ix<$imw; $ix++){
$ndx = imagecolorat($image, $ix, $iy);
if ($ndx != $bg && $ndx !=$bg2){
if ($xmin > $ix){ $xmin = $ix; }
if ($xmax < $ix){ $xmax = $ix; }
if (!isset($ymin)){ $ymin = $iy; }
$ymax = $iy;
if ($first){ $ix = $xmax; $first = false; }
}
}
}
$imw = 1+$xmax-$xmin; // Image width in pixels
$imh = 1+$ymax-$ymin; // Image height in pixels
// Make another image to place the trimmed version in.
$im2 = imagecreatetruecolor($imw+$p[1]+$p[3], $imh+$p[0]+$p[2]);
// Make the background of the new image the same as the background of the old one.
ImageSaveAlpha($im2, true);
ImageAlphaBlending($im2, false);
// Copy it over to the new image.
imagecopy($im2, $image, $p[3], $p[0], $xmin, $ymin, $imw, $imh);
$image = $im2;
// --- ANTIALIASING (downsampling) ---
$imgw_X = imagesx($image);
$imgh_X = imagesy($image);
$image_antialised = imagecreatetruecolor($imgw_X / $antialiasing, $imgh_X / $antialiasing);
ImageSaveAlpha($image_antialised, true);
ImageAlphaBlending($image_antialised, false);
imagecopyresampled($image_antialised, $image, 0,0,0,0, $imgw_X / $antialiasing, $imgh_X / $antialiasing, $imgw_X, $imgh_X);
// ---
###############################################################
## Cache the file
ImagePNG($image_antialised, $this->setting('cachefile')); // ANTIALIASING: $image >>> $image_antialised
}