helper = Helper_E2pdf_Helper::instance(); } /** * Get Base64 Encoded Image * * @param string $image - Image path * * @return mixed - Base64 encoded image OR FALSE */ public function get_image($image) { $source = false; if ($image) { if (0 === strpos($image, site_url())) { $image_path = $this->helper->get('plugin_dir') . '../../../' . substr($image, strlen(site_url())); if (file_exists($image_path)) { $source = base64_encode(file_get_contents($image_path)); } } if (!$source) { $response = $this->get_url($image); if (array_key_exists('content', $response) && $response['content'] !== FALSE) { $source = base64_encode($response['content']); } elseif ($tmp_image = base64_decode($image, true)) { if ($this->get_image_extension($tmp_image)) { $source = $image; } } } } return $source; } /** * Get image by Url * * @param string $url - Url to image * * @return array(); */ public function get_url($url) { $content = @file_get_contents($url); return array( 'headers' => $http_response_header, 'content' => $content ); } public function get_image_extension($image = false) { if (!$image) { return false; } $mime = false; if (function_exists('finfo_open') && function_exists('finfo_buffer')) { $f = finfo_open(); $mime = finfo_buffer($f, $image, FILEINFO_MIME_TYPE); } elseif (function_exists('image_type_to_mime_type') && function_exists('getimagesizefromstring')) { $size = getimagesizefromstring($image); if (isset($size['mime'])) { $mime = $size['mime']; } } switch ($mime) { case 'image/jpeg': $ext = "jpg"; break; case 'image/png': $ext = "png"; break; default: $ext = false; break; } return $ext; } }