• 0

need a little php expertise here.


Question

I just dont get why this isnt working :pinch:

Im working on a dynamic sig program, but this code works, but doesnt draw anything, just a blank image as can be seen from http://yupadog.com/stuff/signature.php

<?php
## Winamp Sig 1.0
## Copyright 2003 Greg Helton
## Dont distrubute or modify without my permission
## http://www.yupadog.com/ ? - ?conr@yupadog.com
unset ($config); ? ? ? ? ? ?//Or this line.
$config = array(); ? ? ? ? ?//Or this line.


$config['font_file'] = '/home/virtual/site1/fst/home/greg/impact.ttf'; ? ?


$config['song_file'] = '/home/virtual/site1/fst/var/www/html/stuff/playing.txt'; ?
 ? ? ? ? ? ? ? ? ? ?	
$config['font_size'] = 16; ? ? ?//Font size in pixels of song
 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//titles display.
 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
$config['font_color_r'] = 0; ? ?//Red component of the colour you want to use
 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//for displaying the song title. For black, set
 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//this as well as font_color_g and font_color_b
 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//all to zero. For white, set all three to 255.

$config['font_color_g'] = 0; ? ?

$config['font_color_b'] = 0; ? ?

$config['text_vertical_offset'] = 45; ? ? ? ? ? //The Y coordinate of where you
 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//want the song title to be
 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//displayed on the canvas. For
 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//the default canvas,
 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//templates/classic_xxx.png, 33
 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//pixels is ideal. If you use a
 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//template other than the
 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//default, play with this value
 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//until you get the text to be
 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//at the ideal vertical
 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//position. Horizontal position
 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//is not specified, as the song
 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//title is automatically
 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//centred on the canvas.

$config['padding'] = 15; ? ?//The amount that you want to indent text
 ? ? ? ? ? ? ? ? ? ? ? ? ? ?//horizontally. This is done so that you end up
 ? ? ? ? ? ? ? ? ? ? ? ? ? ?//with a song name that *just* fits horizontally,
 ? ? ? ? ? ? ? ? ? ? ? ? ? ?//but looks too cramped. This number is for both
 ? ? ? ? ? ? ? ? ? ? ? ? ? ?//left and right indent, so if you stay with the
 ? ? ? ? ? ? ? ? ? ? ? ? ? ?//default of 15 pixels, there will be at least 7.5
 ? ? ? ? ? ? ? ? ? ? ? ? ? ?//pixels to spare on both the left and right sides
 ? ? ? ? ? ? ? ? ? ? ? ? ? ?//of the canvas.

$config['image_base'] = 'base_image';	

$config['image_ext'] = '.jpg'; 
 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 



$song = get_song($config['song_file']); ? ? 

if (!$song) 
{
	$song = "No song name found.";
} 


$img_size = @getimagesize ($config['image_base'] . $config['image_ext']);

$text_size = @size_text($config, $song, @getimagesize($config['image_base'] . $config['image_ext']));

$horiz_indent = (($img_size[0] - $text_size[4]) / 2);

if($config['image_ext'] == '.jpg')
{
	$input = @imagecreatefromjpeg($config['image_base'] . $config['image_ext']);
}
else if($config['image_ext'] == '.png')
{
	$input = @imagecreatefrompng($config['image_base'] . $config['image_ext']);
}

$color = @imagecolorclosest ($input, $config['font_color_r'], $config['font_color_g'], $config['font_color_b']);

@imagettftext ($input,
	$config['font_size'],
 ? 0, ? ? ? ? ? ? ?//angle
 ? $horiz_indent, ?//x
 ? $config['text_vertical_offset'],//y
 ? $color,
 ? $config['font_file'],
 ? $song);
 ? ?
header ('Content-type: image/png');
header ('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
header ('Expires: Fri, 12 May 1978 12:33:00 GMT');
header ('Pragma: no-cache');

// Ouput the image
if($config['image_ext'] == '.jpg')
{
	@imagejpeg($input);
}
else if($config['image_ext'] == '.png')
{
	@imagepng($input);
}


function size_text(&$config, $song_title, $image_size)
{
	$font_size = intval($config['font_size']);
	$padding = intval($config['padding']);

	$text_size = @imagettfbbox ($font_size, 0, $config['font_file'], $song_title);

	while($text_size[4] > ($image_size[0] - $padding))
	{	
 ?$font_size -= 3;
 ?$config['text_vertical_offset'] -= 3;
 ?$text_size = @imagettfbbox($font_size, 0, $config['font_file'], $song_title);
	}
	$config['font_size'] = $font_size;

	return(@imagettfbbox ($font_size, 0, $config['font_file'], $song_title)); //size, angle, name, string
}


function get_song ($song_path) {
$f = fopen($song_path, "r");
$fline = fgets($f,4);
list ($line1, $line2, $line3, $line4) = split("\n", $fline);
$line4 = strip_tags($line4, '<b>');
$songp = str_replace("<br>", "\n", $line4);	


	return($songp);
}
?>

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Well, you've got @'s in front of all the image commands. I'd remove all of them and find any conflicting errors. I'd take a shot at it and say imagettfbox is doing it :)

Link to comment
Share on other sites

  • 0

ok, now this is weird. After removing the @'s I get errors that it cannot find the font i specified. A check of that, and it exists :huh: Any ideas ?

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.