Jump to content

M.O.S. Studios

Members
  • Posts

    282
  • Joined

  • Last visited

Community Answers

  1. M.O.S. Studios's post in Making a Image from CSV was marked as the answer   
    Figured it out.
     
    Here is my round about way to take a CSV file, and visualize it as a table.
     
    <?php require('fpdf.php'); $file = file.csv'; function near5($v){ return round($v * 2) / 2; } function content($file){ $header = array(); if (($handle = fopen($file, "r")) !== FALSE){ $body = array(); $header = fgetcsv($handle); $header[0] = 'Category/Weight(Lbs)'; while (($data = fgetcsv($handle)) !== FALSE){ $body[] = $data; } fclose($handle); } return array($header, $body); } class PDF extends FPDF{ // Simple table function BasicTable($header, $data, $kcal){ // Header $first = 30; foreach($header as $col){ $v = is_numeric($col) ? round(($col*2.2),1) : $col; $this->Cell($first,7,$v,1,0,'C'); $first = 10; } $this->Ln(); // Data foreach($data as $row){ $first = 30; foreach($row as $col){ $v = (is_numeric($col)) ? near5($col/$kcal) : $col; $this->Cell($first,7,$v,1,0,'C'); $first = 10; } $this->Ln(); } } } // Column headings content($file); list($header, $row) = content($file); // Data loading $pdf = new PDF(); $pdf->SetFont('Arial','',5); $pdf->AddPage(); $pdf->BasicTable($header,$row, $kcal); $output = $pdf->Output('S'); $im = new imagick(); $im->setResolution(300, 300); $im->readImageBlob($output); $im->setImageFormat('png'); $im->setImageCompression(imagick::COMPRESSION_JPEG); $im->setImageCompressionQuality(100); $im->borderImage("#ffffff", 20, 20); $im->trimImage(0.3); $im->setImagePage($im->getImageWidth(), $im->getImageHeight(), 0, 0); header("Content-Type: image/" . $im->getImageFormat()); echo $im->getImageBlob(); $im->clear(); $im->destroy(); ?>  
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.