Dreamer76
Through thorns
Создание изображений
Есть у меня такой вот скрипт, который вставляет в картинку случайное число:
<?
{
srand((double) microtime()*100000);
$random = rand();
}
$im = imagecreatefrompng ("but.png");
$width_image = ImageSX($im);
$height_image = ImageSY($im);
$width_image_wo_margins = $width_image - (2 * 1);
$height_image_wo_margins = $height_image - (2 * 1);
$font_size = 10;
do
{
$font_size--;
$bbox=imagettfbbox ($font_size, 0, "arial.ttf", $button_text);
$right_text = $bbox[2];
$left_text = $bbox[0];
$width_text = $right_text - $left_text;
$height_text = abs($bbox[7] - $bbox[1]);
} while ( $font_size>8 &&
( $height_text>$height_image_wo_margins ||
$width_text>$width_image_wo_margins )
);
if ( $height_text>$height_image_wo_margins ||
$width_text>$width_image_wo_margins )
{
echo "Text given will not fit on button.<BR>";
}
else
{
$text_x = $width_image/2.0 - $width_text/2.0;
$text_y = $height_image/2.0 - $height_text/2.0 ;
if ($left_text < 0)
$text_x += abs($left_text);
$above_line_text = abs($bbox[7]);
$text_y += $above_line_text;
$text_y -= 2;
$white = ImageColorAllocate ($im, 255, 255, 255);
$black = ImageColorAllocate ($im, 0, 0, 0);
ImageTTFText ($im, $font_size, 0, $text_x, $text_y, $black, "arial.ttf", $random);
Header ("Content-type: image/png");
ImagePNG ($im);
}
?>
Если его запустить отдельным файлом - все ok.
Но если его вставить модулем в другую прогу, вместо картинки появляется вот что-то типа этого:
‰PNG IHDR–AЂpЙIDATxњн™=kкPЂUљ‚? CtґБ‚P›Z¤„юЂЋD¤ѓї@њЕЎ8tмШЎS‡ЋЕQЉЌЎЁC(R: ‚C)$„пЋд†$Љб—cО3ќјѕ'y љ
и т..п.
В чем проблема?
Есть у меня такой вот скрипт, который вставляет в картинку случайное число:
<?
{
srand((double) microtime()*100000);
$random = rand();
}
$im = imagecreatefrompng ("but.png");
$width_image = ImageSX($im);
$height_image = ImageSY($im);
$width_image_wo_margins = $width_image - (2 * 1);
$height_image_wo_margins = $height_image - (2 * 1);
$font_size = 10;
do
{
$font_size--;
$bbox=imagettfbbox ($font_size, 0, "arial.ttf", $button_text);
$right_text = $bbox[2];
$left_text = $bbox[0];
$width_text = $right_text - $left_text;
$height_text = abs($bbox[7] - $bbox[1]);
} while ( $font_size>8 &&
( $height_text>$height_image_wo_margins ||
$width_text>$width_image_wo_margins )
);
if ( $height_text>$height_image_wo_margins ||
$width_text>$width_image_wo_margins )
{
echo "Text given will not fit on button.<BR>";
}
else
{
$text_x = $width_image/2.0 - $width_text/2.0;
$text_y = $height_image/2.0 - $height_text/2.0 ;
if ($left_text < 0)
$text_x += abs($left_text);
$above_line_text = abs($bbox[7]);
$text_y += $above_line_text;
$text_y -= 2;
$white = ImageColorAllocate ($im, 255, 255, 255);
$black = ImageColorAllocate ($im, 0, 0, 0);
ImageTTFText ($im, $font_size, 0, $text_x, $text_y, $black, "arial.ttf", $random);
Header ("Content-type: image/png");
ImagePNG ($im);
}
?>
Если его запустить отдельным файлом - все ok.
Но если его вставить модулем в другую прогу, вместо картинки появляется вот что-то типа этого:
‰PNG IHDR–AЂpЙIDATxњн™=kкPЂUљ‚? CtґБ‚P›Z¤„юЂЋD¤ѓї@њЕЎ8tмШЎS‡ЋЕQЉЌЎЁC(R: ‚C)$„пЋд†$Љб—cО3ќјѕ'y љ
и т..п.
В чем проблема?
