PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.01.01
E2Pdf – Export Pdf Tool for WordPress v1.01.01
1.32.49 1.32.48 1.32.43 1.32.40 1.32.34 1.32.32 1.32.31 1.32.26 1.32.22 1.32.23 1.32.18 1.32.17 1.32.15 trunk 1.00.00 1.00.13 1.01.01 1.02.02 1.03.07 1.04.07 1.05.03 1.06.02 1.07.11 1.08.00 1.08.06 All 72 releases
e2pdf / classes / helper / e2pdf-image.php

e2pdf-image.php in E2Pdf – Export Pdf Tool for WordPress 1.01.01, at classes/helper/e2pdf-image.php

108 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * E2pdf Image Helper
5 *
6 * @copyright Copyright 2017 https://e2pdf.com
7 * @license GPL v2
8 * @version 1
9 * @link https://e2pdf.com
10 * @since 0.00.01
11 */
12 if (!defined('ABSPATH')) {
13 die('Access denied.');
14 }
15
16 class Helper_E2pdf_Image {
17
18 private $helper;
19
20 public function __construct() {
21 $this->helper = Helper_E2pdf_Helper::instance();
22 }
23
24 /**
25 * Get Base64 Encoded Image
26 *
27 * @param string $image - Image path
28 *
29 * @return mixed - Base64 encoded image OR FALSE
30 */
31 public function get_image($image) {
32
33 $source = false;
34
35 if ($image) {
36
37 if (0 === strpos($image, site_url())) {
38 $image_path = $this->helper->get('plugin_dir') . '../../../' . substr($image, strlen(site_url()));
39 if (file_exists($image_path)) {
40 $source = base64_encode(file_get_contents($image_path));
41 }
42 }
43
44 if (!$source) {
45 $response = $this->get_url($image);
46 if (array_key_exists('content', $response) && $response['content'] !== FALSE) {
47 $source = base64_encode($response['content']);
48 } elseif ($tmp_image = base64_decode($image, true)) {
49 if ($this->get_image_extension($tmp_image)) {
50 $source = $image;
51 }
52 }
53 }
54 }
55 return $source;
56 }
57
58 /**
59 * Get image by Url
60 *
61 * @param string $url - Url to image
62 *
63 * @return array();
64 */
65 public function get_url($url) {
66 $content = @file_get_contents($url);
67 return array(
68 'headers' => $http_response_header,
69 'content' => $content
70 );
71 }
72
73 public function get_image_extension($image = false) {
74
75 if (!$image) {
76 return false;
77 }
78
79 $mime = false;
80 if (function_exists('finfo_open') && function_exists('finfo_buffer')) {
81 $f = finfo_open();
82 $mime = finfo_buffer($f, $image, FILEINFO_MIME_TYPE);
83 } elseif (function_exists('image_type_to_mime_type') && function_exists('getimagesizefromstring')) {
84 $size = getimagesizefromstring($image);
85 if (isset($size['mime'])) {
86 $mime = $size['mime'];
87 }
88 }
89
90 switch ($mime) {
91 case 'image/jpeg':
92 $ext = "jpg";
93 break;
94
95 case 'image/png':
96 $ext = "png";
97 break;
98
99 default:
100 $ext = false;
101 break;
102 }
103
104 return $ext;
105 }
106
107 }
108