<?php
/**
 * Data
 *
 * @author Arkadiusz Rychlik <areksoft@gmail.com>
 */
class Eppe_Data {
	
	static function serializeRowColumnValue($rawValue){
		return json_encode($rawValue);
	}
	
	static function deserializeRowColumnValue($serializedValue){
		return json_decode($serializedValue);
	}
	
	static function base64EncodeImage($imagePath){
        $imgtype = array('jpg', 'gif', 'png');
        $filename = file_exists($imagePath) ? htmlentities($imagePath) : die('Image file name does not exist');
        $filetype = pathinfo($filename, PATHINFO_EXTENSION);
        if (in_array($filetype, $imgtype)){
            $imgbinary = fread(fopen($filename, "r"), filesize($filename));
        } else {
            die ('Invalid image type, jpg, gif, and png is only allowed');
        }
        return 'data:image/' . $filetype . ';base64,' . base64_encode($imgbinary);
	}

}