Loading modules/commerce_billy_pdf/commerce_billy_pdf.module +25 −1 Original line number Diff line number Diff line Loading @@ -229,11 +229,35 @@ function commerce_billy_pdf_commerce_order_view($order, $view_mode) { $logo_path = DRUPAL_ROOT . '/' . $logo_path; } $order->content['invoice_logo'] = array( '#value' => $logo_path, '#value' => _commerce_billy_pdf_base64_image($logo_path), ); } } /** * Convert image path into Base64 image. * * @param string $image_path * Valid image path to convert. * * @return string * Base64 image. */ function _commerce_billy_pdf_base64_image($image_path) { // Check if image exists in local file system. if (file_exists($image_path)) { $image_data = base64_encode(file_get_contents($image_path)); $mime_type = mime_content_type($image_path); // Image source format: "data:{mime};base64,{data};" return 'data:' . $mime_type . ';base64,' . $image_data; } // If the file cannot be found, post a watchdog message and display no logo. watchdog('commerce_billy_pdf', 'Invoice logo does not exist or cannot be found: %path', array('%path' => $image_path), WATCHDOG_ERROR); return ''; } /** * Transforms HTML to PDF and outputs it to the browser. * Loading Loading
modules/commerce_billy_pdf/commerce_billy_pdf.module +25 −1 Original line number Diff line number Diff line Loading @@ -229,11 +229,35 @@ function commerce_billy_pdf_commerce_order_view($order, $view_mode) { $logo_path = DRUPAL_ROOT . '/' . $logo_path; } $order->content['invoice_logo'] = array( '#value' => $logo_path, '#value' => _commerce_billy_pdf_base64_image($logo_path), ); } } /** * Convert image path into Base64 image. * * @param string $image_path * Valid image path to convert. * * @return string * Base64 image. */ function _commerce_billy_pdf_base64_image($image_path) { // Check if image exists in local file system. if (file_exists($image_path)) { $image_data = base64_encode(file_get_contents($image_path)); $mime_type = mime_content_type($image_path); // Image source format: "data:{mime};base64,{data};" return 'data:' . $mime_type . ';base64,' . $image_data; } // If the file cannot be found, post a watchdog message and display no logo. watchdog('commerce_billy_pdf', 'Invoice logo does not exist or cannot be found: %path', array('%path' => $image_path), WATCHDOG_ERROR); return ''; } /** * Transforms HTML to PDF and outputs it to the browser. * Loading