Ejemplo n.º 1
0
function composite_image($origin, $comp, $out_file)
{
    if (file_exists($origin) && file_exists($comp)) {
        $os = image_size($origin);
        $cs = image_size($comp);
        $w = $os[0];
        $h = $os[1];
        $cw = $cs[0];
        $ch = $cs[1];
        $x = ($w - $cw) / 2;
        $y = ($h - $ch) / 2;
        if (extension_loaded('imagick')) {
            $i = new Imagick($origin);
            $c = new Imagick($comp);
            $i->compositeImage($c, Imagick::COMPOSITE_DEFAULT, $x, $y);
            $i->writeImage($out_file);
            return true;
        }
        if (extension_loaded('gd')) {
            $ext = image_type($origin);
            // Reading the origin image
            if ($ext == 'jpg' || $ext == 'jpeg') {
                $im = imagecreatefromjpeg($origin);
            } else {
                $im = imagecreatefrompng($origin);
            }
            $ext = image_type($comp);
            // Reading the composite image
            if ($ext == 'jpg' || $ext == 'jpeg') {
                $overlay = imagecreatefromjpeg($comp);
            } else {
                $overlay = imagecreatefrompng($comp);
            }
            imagecopymerge($im, $overlay, $x, $y, 0, 0, $cw, $ch, 100);
            $ext = image_type($out_file);
            if ($ext == 'jpg' || $ext == 'jpeg') {
                imagejpeg($im, $out_file);
            } else {
                imagepng($im, $out_file);
            }
            imagedestroy($overlay);
            imagedestroy($im);
        }
    }
    return false;
}
Ejemplo n.º 2
0
function print_image($name, $type, $width, $height, $alt, $title, $style = "")
{
    if (preg_match('/\\/admin/', $_SERVER['PHP_SELF'])) {
        $path = '../';
    } else {
        $path = '';
    }
    switch ($type) {
        case "artist":
            $path .= $_CONFIG["site_url"] . 'z_uploads/artist_gallery/thumb_artist_images/';
            break;
    }
    $name = $path . $name;
    if (is_dir($name)) {
        $name .= "noimage.gif";
    } elseif (!file_exists($name)) {
        $pieces = explode('/', $name);
        $pieces[sizeof($pieces) - 1] = 'noimage.gif';
        $name = implode('/', $pieces);
    }
    $property = image_size($name);
    //calling the function which finds the size of picture
    $p_width = $property[0];
    //assigning the picture width //actual width of the image
    $p_height = $property[1];
    //actual height of the image
    $nam = $name;
    if ($width < $p_width and $height < $p_height) {
        $xw = $p_width / $width;
        $yh = $p_height / $height;
        if ($xw > $yh) {
            $wd = $width;
            //$ht = $height;
            ?>
<img src="<?php 
            echo $nam;
            ?>
" border="0" alt="<?php 
            echo $alt;
            ?>
" title="<?php 
            echo $title;
            ?>
" width="<?php 
            echo $wd;
            ?>
"  style="<?php 
            echo $style;
            ?>
" /><?php 
        } else {
            //$wd = $width;
            $ht = $height;
            ?>
<img src="<?php 
            echo $nam;
            ?>
" border="0" alt="<?php 
            echo $alt;
            ?>
" title="<?php 
            echo $title;
            ?>
"  height="<?php 
            echo $ht;
            ?>
" style="<?php 
            echo $style;
            ?>
" /><?php 
        }
    } else {
        if ($width < $p_width && $height >= $p_height) {
            //echo '<br>picture width exceeds';
            ?>
<img src="<?php 
            echo $name;
            ?>
" border="0" alt="<?php 
            echo $alt;
            ?>
" title="<?php 
            echo $title;
            ?>
" width="<?php 
            echo $width;
            ?>
" style="<?php 
            echo $style;
            ?>
" /><?php 
        } else {
            if ($height < $p_height && $width >= $p_width) {
                //echo '<br>picture height exceeds ';
                ?>
<img src="<?php 
                echo $nam;
                ?>
" border="0" alt="<?php 
                echo $alt;
                ?>
" title="<?php 
                echo $title;
                ?>
" height=<?php 
                echo $height;
                ?>
 style="<?php 
                echo $style;
                ?>
" /><?php 
            } else {
                //echo '<br>picture is small enough';
                ?>
<img src="<?php 
                echo $nam;
                ?>
" border="0" alt="<?php 
                echo $alt;
                ?>
" title="<?php 
                echo $title;
                ?>
" style="<?php 
                echo $style;
                ?>
" /><?php 
                //if the height and width of the input image is greater than the actual size
            }
        }
    }
}