• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 539
  • Last Modified:

Using Images in FPDF

I've been using a few FPDF routines in my project for years without a hitch. I've also used the Image function to successfully place a couple of PNG flags in the document. Now I'm trying to place a few extra smaller flags in a few places in the document. I'm using almost the exact same code which renders them fine and yet I can't get it working. Can someone take a look at the code snippets below and see if they can see anything wrong please?

Firstly, this is how I call the flags with success earlier in the document:
if($grph==1) {
	$this->Image("images/flags/".$data['home_cc'].".png", 15, $y, 7, 3.5);
	$this->Image("images/flags/".$data['host_cc'].".png", 15, $y+5, 7, 3.5);

Open in new window

No problems there. Then I try to call almost the same code within a function which prints a line at a time which I call from a FOREACH loop. The loop looks like this:
foreach($data['pre_tax_remuneration'] as $row) {
	if($row[3]==1) $fl=$data['home_cc']; else $fl=$data['host_cc'];
	$this->Breakdown_Values($row[0], $row[$curr+1], $x1, $fl);

Open in new window

$row[3] is just a two letter string of the country and I'#ve checked that that is making it through to the function correctly. So, the function is:
function Breakdown_Values($title, $value, $x, $fl) {
global $c;
$this->SetTextColor($c['txt_2']['r'], $c['txt_2']['g'], $c['txt_2']['b']);
	$this->SetTextColor($c['txt_1']['r'], $c['txt_1']['g'], $c['txt_1']['b']);
	if($fl!=0) {
		$this->Image("images/flags/".$fl.".png", $x+1, $y, 3, 2);

Open in new window

$c is just an array of a colour. I've tried playing about with the $x and $y values just to get it placed somewhere in the document but it never seems to appear.

Can anyone spot why? This is really bugging me ebcause I've now spent over two hours trying everything I can think of but with no success.

The manual for the FPDF is here and I use version 1.6.

I greatly appreciate any help/input.

1 Solution
worldofwiresAuthor Commented:
Cracked it. It was my IF statement. I changed it to:
	if(!is_numeric($fl)) {
		$this->Image("images/flags/".$fl.".png", $x+1, $y, 3, 2);

Open in new window

and it works. Not sure why though but it's sorted. I was passing a 0 value for teh rows where I didn't want a flag and a string when I did so I guess there is a lesson there about mixing up your variables.

I am going to rewrite the function call so I don't have to specify the the 0 when I don't want flags. So it will then look like:
function Breakdown_Values($title, $value, $x, $fl=NULL) {

Open in new window

function Breakdown_Values($title, $value, $x, $fl=0) {

Open in new window

to keep my !is_numeric IF stament working. Anyone want to advise/opine on best practises on this front?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now