Location: PHPKode > projects > Pindorama > pindorama/active/components/image.php
<?php
/**
*                                                          
* @name    Pindorama image funcions                    
* @version 0.1
* @author  Guilherme Capilé <hide@address.com>           
*                                                          
*/
/*
    $acom["image.create_image"]="/_images/labels";
    */
    
/**
*                                                          
* @name        pin_create_image_config
* @deprecated  
* @version     0.11
*
* @author      Guilherme Capilé <hide@address.com>
*
* @param       $url (Default = "")
*
* @global      $acom
* @global      $c
* @global      $str
* @global      $format
* @global      $ci
* @global      $ic
* @global      $d
* @global      $box
* 
* @see         pin_redirect()
*
* @return      
*/    
function pin_create_image_config($url = "")
{
    global $acom, $c, $str, $format, $ci, $ic, $d, $box;
    // debug: echo "image ($url)";
    $ci["base_dir"] = $c["etc"]."image";
    $ci["fonts_dir"] = $ci["base_dir"]."/fonts/";
    $ci["base_url"] = "/_images/titles";
    $ci["cache_dir"] = $c["www"].$ci["base_url"];
    if ($url == "") {
        $ci["url"] = $_SERVER["PHP_SELF"];
    } else {
        $ci["url"] = $url;
    }
    $ci["img_url"] = substr($ci["url"], strlen($ci["base_url"]));
    $ci["translate"] = array("_"=>" ");
    $ci["filename"] = $ci["cache_dir"].$ci["img_url"];
    if ($ci["img_url"] == "") {
        pin_redirect($ci["url"]."/");
    } else if ($ci["img_url"] == "/") {
        header ("Content-type: text/plain");
        print_r($ci);
        echo "\n".urlencode("?").$ic;
        return false;
    } else {
        $d["width"] = 150;
        $d["height"] = 15;
        $d["color"] = "#666666";
        $d["color-alpha"] = 0;
        $d["background"] = "#ffffff";
        $d["background-alpha"] = 0;
        $d["font-size"] = 9;
        $d["padding-left"] = 0;
        $d["padding-top"] = 0;
        $d["padding-right"] = 0;
        $d["padding-bottom"] = 0;
        $d["angle"] = 0;
        $d["src"] = "univc.ttf";
        $d["overflow"] = "visible";
        
        if (preg_match("/^\/([^\/]+)\/(.+)\.(png|jpg)$/", $ci["img_url"], $m)) {
            $class = $m[1];
            $str = strtr($m[2], $ci["translate"]);
            $format = $m[3];
            require($ci["base_dir"]."/image-classes.php");
            if (is_array($ic[$class])) {
                $d = array_merge($d, $ic[$class]);
            }
        } else if (preg_match("/^\/(.+)\.(png|jpg)$/", $ci["img_url"], $m)) {
            $str = strtr($m[1], $ci["translate"]);
            $format = $m[2];
        } else {
            $str = strtr(substr($ci["img_url"], 1), $ci["translate"]);
            $format = "png";
        }
        return true;
    }
}


/**
*                                                          
* @name        pin_create_image
* @deprecated  
* @version     0.11
*
* @author      Guilherme Capilé <hide@address.com>
*
* @global      $acom
* @global      $c
* @global      $str
* @global      $format
* @global      $ci
* @global      $ic
* @global      $d
* @global      $box
* 
* @see         pin_create_image_config()
* @see         pin_make_pathtofile()
* @see         pin_output_header()
*
* @return      
*/   
function pin_create_image()
{
    global $acom, $c, $str, $format, $ci, $ic, $d, $box;
    if (pin_create_image_config()) {
        if ($d["content"] != "") {
            $str = $d["content"];
        }
        if (!is_file($ci["filename"]) || (time() - filemtime($ci["filename"])) > 1) {
            pin_make_pathtofile($ci["filename"]);

            if ($d["width"] == 0 || $d["height"] == 0 || $d["overflow"] != "hidden") {
                $box = imagettfbbox ( $d["font-size"], $d["angle"], $ci["fonts_dir"].$d["src"], $str);
                if ($d["width"] == 0 || $d["overflow"] != "hidden") {
                    $d["width"] = $d["padding-left"] + $box[2] - $box[0] + $d["padding-right"];
                }
                if ($d["height"] == 0 || $d["overflow"] != "hidden") {
                    $d["height"] = $d["padding-top"] + $box[6] - $box[0] + $d["padding-bottom"] + $d["font-size"];
                }
            }
            $d["color"] = pin_split_color($d["color"], $d["color-alpha"]);
            $d["background"] = pin_split_color($d["background"], $d["background-alpha"]);
            $im = @imagecreate ($d["width"], $d["height"]) 
               or die ("Cannot Initialize new GD image stream");
            $bkg   = imagecolorallocatealpha ($im, $d["background"]["r"], $d["background"]["g"], $d["background"]["b"], $d["background"]["a"]); 
            $color = imagecolorallocatealpha ($im, $d["color"]["r"], $d["color"]["g"], $d["color"]["b"], $d["color"]["a"]);
            imagettftext($im, $d["font-size"], $d["angle"], $d["padding-left"], $d["padding-top"] + $d["font-size"], $color, $ci["fonts_dir"].$d["src"], $str);
            imagepng ($im, $ci["filename"]);
            imagedestroy ($im);
        }
        pin_output_header ($ci["filename"], TRUE, $format);
        echo file_get_contents($ci["filename"]);   
    }
}


/**
*                                                          
* @name        pin_create_image_from_doc
* @deprecated  
* @version     0.11
*
* @author      Guilherme Capilé <hide@address.com>
*
* @global      $acom
* @global      $c
* @global      $str
* @global      $format
* @global      $ci
* @global      $ic
* @global      $d
* @global      $box
* 
* @see         pin_create_image_config()
* @see         pin_read_xpath()
* @see         pin_create_image()
*
* @return      
*/   
function pin_create_image_from_doc()
{
    global $acom, $c, $str, $format, $ci, $ic, $d, $box;
    if (pin_create_image_config()) {
        $ci["base_url"] = "/_images/titles";
        if (preg_match("/([0-9]+)(\.([0-9]+))?/", $str, $matches)) {
            if ($matches[3] != "") {
                $xp = "/xpml/resource[substring-after(@id, '#') = '{$matches[3]}']/*[name() = 'name' or name() = 'title'][1]";
            } else {
                $xp = "/xpml/meta/title";
            }
            $title = pin_read_xpath($xp, "db:www_n{$matches[1]}");
            if ($title[0] != "") {
                
                $d["content"] = str_replace("’", "'", html_entity_decode($title[0], ENT_QUOTES));
            }
        }
        pin_create_image();
    }
} //create_image_from_doc


/**
*                                                          
* @name        pin_create_image_info
* @deprecated  
* @version     0.11
*
* @author      Guilherme Capilé <hide@address.com>
*
* @param       $url (Default = "")
*
* @global      $acom
* @global      $c
* @global      $str
* @global      $format
* @global      $ci
* @global      $ic
* @global      $d
* @global      $box
* 
* @see         pin_create_image_config()
* @see         pin_split_color
*
* @return      
*/   
function pin_create_image_info($url = "")
{
    global $acom, $c, $str, $format, $ci, $ic, $d, $box;
    if (pin_create_image_config($url)) {
        $ci["base_url"] = "/_images/titles";
        if (preg_match("/([0-9]+)(\.([0-9]+))?/", $str, $matches)) {
            if ($matches[3] != "") {
                $xp = "/xpml/resource[substring-after(@id, '#') = '{$matches[3]}']/*[name() = 'name' or name() = 'title'][1]";
            } else {
                $xp = "/xpml/meta/title";
            }
            $title = pin_read_xpath($xp, "db:www_n{$matches[1]}");
            if ($title[0] != "") {
                
                $d["content"] = str_replace("’", "'", html_entity_decode($title[0], ENT_QUOTES));
            }
        }
        if ($d["content"] != "") {
            $str = $d["content"];
        }
        if ($d["width"] == 0 || $d["height"] == 0 || $d["overflow"] != "hidden") {
            $box = @imagettfbbox ( $d["font-size"], $d["angle"], $ci["fonts_dir"].$d["src"], $str);
            if ($d["width"] == 0 || $d["overflow"] != "hidden") {
                $d["width"] = $d["padding-left"] + $box[2] - $box[0] + $d["padding-right"];
            }
            if ($d["height"] == 0 || $d["overflow"] != "hidden") {
                $d["height"] = $d["padding-top"] + $box[6] - $box[0] + $d["padding-bottom"] + $d["font-size"];
            }
        }
        $d["color"] = pin_split_color($d["color"], $d["color-alpha"]);
        $d["background"] = pin_split_color($d["background"], $d["background-alpha"]);
    }
    return $d;
} //create_image_from_doc

/**
*                                                          
* @name        pin_split_color
* @deprecated  
* @version     0.11
*
* @author      Guilherme Capilé <hide@address.com>
*
* @param       $color
* @param       $alpha (Default = 0)
*
* @see         pin_create_image_config()
* @see         pin_split_color
*
* @return      
*/   
function pin_split_color($color, $alpha = 0)
{
    $color = str_replace("#", "", $color);
    $color =  array(
       "r" => hexdec(substr($color, 0, 2)),
       "g" => hexdec(substr($color, 2, 2)),
       "b" => hexdec(substr($color, 4, 2)),
       "a" => $alpha);
    return $color;
}

?>
Return current item: Pindorama