<commit_before><?php

namespace Heyday\SilverStripe\WkHtml;

use ViewableData;

/**
 * Class TemplateHelper
 * @package Heyday\SilverStripe\WkHtml
 */
class TemplateHelper extends ViewableData
{
    /**
     * @param $css
     * @return string
     */
    public function EmbedCss($css)
    {
        if (file_exists(BASE_PATH . $css)) {
            return '<style>' . file_get_contents(BASE_PATH . $css) . '</style>';
        }
    }
    /**
     * @param $image
     * @return string
     */
    public function EmbedBase64Image($image)
    {
        if (file_exists(BASE_PATH . $image)) {
            return 'data:image/png;base64,' . base64_encode(file_get_contents(BASE_PATH . $image));
        }
    }
}<commit_msg>UPDATE: Mime type guessing for data URL helper<commit_after><?php

namespace Heyday\SilverStripe\WkHtml;

use ViewableData;

/**
 * Class TemplateHelper
 * @package Heyday\SilverStripe\WkHtml
 */
class TemplateHelper extends ViewableData
{
    /**
     * @param $css
     * @return string
     */
    public function EmbedCss($css)
    {
        if (file_exists(BASE_PATH . $css)) {
            return '<style>' . file_get_contents(BASE_PATH . $css) . '</style>';
        }
    }
    /**
     * Make a data URL from an image file
     * @param $path
     * @return string
     */
    public function EmbedBase64Image($path)
    {
        $path = BASE_PATH . $path;

        if (file_exists($path)) {
            $mime = $this->getMimeType($path);

            if ($mime) {
                return 'data:'.$mime.';base64,' . base64_encode(file_get_contents($path));
            }
        }
    }
    /**
     * Guess mime type based on file extension
     * @param  $path
     * @return string
     */
    public function getMimeType($path)
    {
        $mimeTypes = array(
            'png' => 'image/png',
            'jpe' => 'image/jpeg',
            'jpeg' => 'image/jpeg',
            'jpg' => 'image/jpeg',
            'gif' => 'image/gif',
            'bmp' => 'image/bmp',
            'ico' => 'image/vnd.microsoft.icon',
            'tiff' => 'image/tiff',
            'tif' => 'image/tiff',
            'svg' => 'image/svg+xml',
            'svgz' => 'image/svg+xml'
        );

        $ext = pathinfo($path, PATHINFO_EXTENSION);
        if (array_key_exists($ext, $mimeTypes)) {
            return $mimeTypes[$ext];
        }
    }
}
{'fraction_non_alphanumeric': 0.14792899408284024, 'fraction_numerical': 0.00507185122569738, 'mean_word_length': 1.911439114391144, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7052769', 'n_tokens_mistral': 790, 'n_tokens_neox': 761, 'n_words': 150}