Microweber\Providers\MediaManager::pixum_img PHP Method

pixum_img() public method

public pixum_img ( )
    public function pixum_img()
    {
        $mime_type = 'image/png';
        $extension = '.png';
        $cache_folder = media_base_path() . 'pixum' . DS;
        $cache_folder = normalize_path($cache_folder, true);
        if (!is_dir($cache_folder)) {
            mkdir_recursive($cache_folder);
        }
        if (isset($_REQUEST['width'])) {
            $w = $_REQUEST['width'];
        } else {
            $w = 1;
        }
        if (isset($_REQUEST['height'])) {
            $h = $_REQUEST['height'];
        } else {
            $h = 1;
        }
        $h = intval($h);
        $w = intval($w);
        if ($h == 0) {
            $h = 1;
        }
        if ($w == 0) {
            $w = 1;
        }
        $hash = 'pixum-' . $h . 'x' . $w;
        $cachefile = $cache_folder . '/' . $hash . $extension;
        header('Content-Type: image/png');
        if (!file_exists($cachefile)) {
            $img = imagecreatetruecolor($w, $h);
            $white = imagecolorallocatealpha($img, 239, 236, 236, 0);
            imagefill($img, 0, 0, $white);
            imagealphablending($img, false);
            imagesavealpha($img, true);
            imagepng($img, $cachefile);
            imagedestroy($img);
            $fp = fopen($cachefile, 'rb');
            fpassthru($fp);
            exit;
        } else {
            $fp = fopen($cachefile, 'rb');
            fpassthru($fp);
            exit;
        }
    }