Logo Search packages:      
Sourcecode: acidbase version File versions  Download package

Cpdf::addImage ( &$  img,
x,
y,
w = 0,
h = 0,
quality = 75 
)

add an image into the document, from a GD object this function is not all that reliable, and I would probably encourage people to use the file based functions

Definition at line 2870 of file class.pdf.php.

References addJpegImage_common().

                                                    {
  // add a new image into the current location, as an external object
  // add the image at $x,$y, and with width and height as defined by $w & $h
  
  // note that this will only work with full colour images and makes them jpg images for display
  // later versions could present lossless image formats if there is interest.
  
  // there seems to be some problem here in that images that have quality set above 75 do not appear
  // not too sure why this is, but in the meantime I have restricted this to 75.  
  if ($quality>75){
    $quality=75;
  }

  // if the width or height are set to zero, then set the other one based on keeping the image
  // height/width ratio the same, if they are both zero, then give up :)
  $imageWidth=imagesx($img);
  $imageHeight=imagesy($img);
  
  if ($w<=0 && $h<=0){
    return;
  }
  if ($w==0){
    $w=$h/$imageHeight*$imageWidth;
  }
  if ($h==0){
    $h=$w*$imageHeight/$imageWidth;
  }
  
  // gotta get the data out of the img..

  // so I write to a temp file, and then read it back.. soo ugly, my apologies.
  $tmpDir='/tmp';
  $tmpName=tempnam($tmpDir,'img');
  imagejpeg($img,$tmpName,$quality);
  $fp=fopen($tmpName,'rb');

  $tmp = get_magic_quotes_runtime();
  set_magic_quotes_runtime(0);
  $fp = @fopen($tmpName,'rb');
  if ($fp){
    $data='';
    while(!feof($fp)){
      $data .= fread($fp,1024);
    }
    fclose($fp);
  } else {
    $error = 1;
    $errormsg = 'trouble opening file';
  }
//  $data = fread($fp,filesize($tmpName));
  set_magic_quotes_runtime($tmp);
//  fclose($fp);
  unlink($tmpName);
  $this->addJpegImage_common($data,$x,$y,$w,$h,$imageWidth,$imageHeight);
}

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index