# e2pdf/1.05.03/classes/helper/e2pdf-image.php

E2Pdf – Export Pdf Tool for WordPress, version 1.05.03. 113 lines.

- Page: https://pluginprobe.com/plugins/e2pdf/1.05.03/code/classes/helper/e2pdf-image.php
- Raw: https://pluginprobe.com/plugins/e2pdf/1.05.03/raw/classes/helper/e2pdf-image.php
- Modified: 2019-03-12T13:29:06+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/e2pdf/1.05.03/code/classes/helper/e2pdf-image.php#L10-L20`.

```php
<?php

/**
 * E2pdf Image Helper
 * 
 * @copyright  Copyright 2017 https://e2pdf.com
 * @license    GPL v2
 * @version    1
 * @link       https://e2pdf.com
 * @since      0.00.01
 */
if (!defined('ABSPATH')) {
    die('Access denied.');
}

class Helper_E2pdf_Image {

    private $helper;

    public function __construct() {
        $this->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) {
                if ($body = $this->get_by_url($image)) {
                    $source = base64_encode($body);
                } 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_by_url($url) {

        $response = wp_remote_get($url, array(
            'timeout' => 30,
            'sslverify' => false
        ));

        if (wp_remote_retrieve_response_code($response) === 200) {
            return wp_remote_retrieve_body($response);
        } else {
            return '';
        }
    }

    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;
    }

}

```
