// load the 'fpdf' extension
// just for demonstration purpose, the OP gets the content from a database instead
$h_img = fopen('img.jpg', "rb");
$img = fread($h_img, filesize('img.jpg'));
// prepare a base64 encoded "data url"
$pic = 'data://text/plain;base64,' . base64_encode($img);
// extract dimensions from image
$info = getimagesize($pic);
// create a simple pdf document to prove this is very well possible:
$pdf = new FPDF();
$pdf->Image($pic, 10, 30, $info, $info, 'jpg');
@MonkeyZeus Of course the fopen() fread() fclose() sequence is not required at all for the OP. That is why I added that remark to it clearly stating that fact. The code is meant as a primitive example to demonstrate the point here. Code examples should be complete in themselves if possible, so that they can be tried with as little implicit requirements as possible. Glad I could be of help and shed some light here. Have fun!
@RichardGriffiths That is a completely separate question about fpdf I'd say. In my eyes what you ask does make that much sense: pdf is a format to place elements in a very precise and distinct manner, quite unlike html. There is a workaroud however I remember using in tcpdf: it is easy in php to ask the dimensions of an image, you can use those values in the ->Image() call. Again you don't really need a physical file for that, you can use the same url scheme as shown in this answer here. Oh, and for flexible and convenient layouting: github.com/arkascha/php-urithmetic ;-)
An interesting debate and another good answer. One issue however is the sizing of the image. In your example you have 40 x 40. I realise this could be altered but could it be dynamic ie to handle portrait vs landscape?
As mentioned in the comments above this is possible by using a stream ("data url") to hand over the image data to the fpdf library without writing physical files to disk:
If this is a good advice is another question, this is merely meant to prove that this is possible...
Interesting proposal but I'm not quite sure I understand your example; why use fopen() at all? Could OP simply use $pdf->Image('data://text/plain;base64,'.base64_encode($row['photoData']), 10, 30, 40, 40, 'jpg'); and avoid the calls to fopen(), fread(), and fclose()? If so then this answer is better than mine because the only disk access would be the DB read operation for photoData. I am personally not familiar with this part 'data://text/plain;base64,' so maybe that is the source of my confusion.