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

E2Pdf – Export Pdf Tool for WordPress, version 1.01.01. 108 lines.

- Page: https://pluginprobe.com/plugins/e2pdf/1.01.01/code/classes/helper/e2pdf-image.php
- Raw: https://pluginprobe.com/plugins/e2pdf/1.01.01/raw/classes/helper/e2pdf-image.php
- Modified: 2018-11-07T14:59:18+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.01.01/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) {
                $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;
    }

}

```
