Exemple #1
0
function createThumb($source, $destination, $saveName, $targetWidth, $targetHeight)
{
    // Get image size
    $originalSize = getimagesize($source);
    // Set thumb image size
    $targetSize = setWidthHeight($originalSize[0], $originalSize[1], $targetWidth, $targetHeight);
    // Get image extension
    $ext = getExtension($source);
    // Determine source image type
    if ($ext == 'gif') {
        $src = imagecreatefromgif($source);
    } elseif ($ext == 'png') {
        $src = imagecreatefrompng($source);
    } elseif ($ext == 'jpg' || $ext == 'jpeg') {
        $src = imagecreatefromjpeg($source);
    } else {
        return 'Unknow image type !';
    }
    // Copy image
    $dst = imagecreatetruecolor($targetSize[0], $targetSize[1]);
    imagecopyresampled($dst, $src, 0, 0, 0, 0, $targetSize[0], $targetSize[1], $originalSize[0], $originalSize[1]);
    if (!file_exists($destination)) {
        if (!createRDir($destination)) {
            return 'Unabled to create destination folder !';
        }
    }
    // destination + fileName
    $thumbName = $destination . '/' . $saveName . '.' . $ext;
    if ($ext == 'gif') {
        imagegif($dst, $thumbName);
    } else {
        if ($ext == 'png') {
            imagepng($dst, $thumbName);
        } else {
            if ($ext == 'jpg' || $ext == 'jpeg') {
                imagejpeg($dst, $thumbName, 100);
            } else {
                return 'Fail to create thumb !';
            }
        }
    }
    imagedestroy($dst);
    imagedestroy($src);
    return $thumbName;
}
Exemple #2
0
					</div>
					<br style="clear: both;" />
					<hr />
					<?php 
                //Now, we have to go through the table and output all fields. Start with the images.
                $acceptfields = $thepage->getacceptfields();
                for ($i = 0; $i < count($acceptfields); $i++) {
                    $curfield = new acceptfield("", "", "", "", "", "");
                    $curfield = $acceptfields[$i];
                    if ($curfield->gettypeoffield() == "file") {
                        //Then we need to display the image, provided there is one.
                        if ($validdata[$curfield->getnameoffield()] != "none") {
                            //Then display the image.
                            $displayimg = $thepage->getfoldername() . "/" . $thepage->getimagefolder() . $validdata[$curfield->getnameoffield()];
                            $oldimgsize = getimagesize($displayimg);
                            $newimgsize = setWidthHeight($oldimgsize[0], $oldimgsize[1], $thepage->getmaxdisplaywidth(), $thepage->getmaxdisplayheight());
                            //Then echo the image.
                            ?>
<img src="<?php 
                            echo $displayimg;
                            ?>
" width="<?php 
                            echo $newimgsize[0];
                            ?>
" height="<?php 
                            echo $newimgsize[1];
                            ?>
" alt="" border="0" /><br /><br /><?php 
                        }
                        unset($displayimg);
                        unset($oldimgsize);
Exemple #3
0
<h1>News along the path</h1>
<?php 
if ($nquery = mysql_query("SELECT * FROM news ORDER BY displayorder DESC")) {
    while ($ndata = mysql_fetch_array($nquery)) {
        ?>
<div id="<?php 
        echo $ndata['newsid'];
        ?>
"><p style="font-weight: bold;"><?php 
        echo stripslashes($ndata['title']);
        ?>
</p></div><?php 
        if ($ndata['image'] != "" && $ndata['image'] != "none") {
            $theimg = "siteadmin/news/images/" . $ndata['image'];
            $oldsize = getimagesize($theimg);
            $newsize = setWidthHeight($oldsize[0], $oldsize[1], 250, 250);
            ?>
<img src="<?php 
            echo $theimg;
            ?>
" align="right" alt="" style="margin: 4px; border: none; width: <?php 
            echo $newsize[0];
            ?>
px; height: <?php 
            echo $newsize[1];
            ?>
px;" /><?php 
        }
        ?>
<p><?php 
        echo stripslashes(nl2br($ndata['content']));
function thumb_image($file, $width, $height, $folder)
{
    if (!file_exists($folder . $file)) {
        return false;
    }
    // không tìm thấy file
    if ($cursize = getimagesize($folder . $file)) {
        $newsize = setWidthHeight($cursize[0], $cursize[1], $width, $height);
        $info = pathinfo($file);
        $dst = imagecreatetruecolor($newsize[0], $newsize[1]);
        $types = array('jpg' => array('imagecreatefromjpeg', 'imagejpeg'), 'JPG' => array('imagecreatefromjpeg', 'imagejpeg'), 'gif' => array('imagecreatefromgif', 'imagegif'), 'GIF' => array('imagecreatefromgif', 'imagegif'), 'PNG' => array('imagecreatefrompng', 'imagepng'), 'png' => array('imagecreatefrompng', 'imagepng'));
        $func = $types[$info['extension']][0];
        $src = $func($folder . $file);
        imagecopyresampled($dst, $src, 0, 0, 0, 0, $newsize[0], $newsize[1], $cursize[0], $cursize[1]);
        $func = $types[$info['extension']][1];
        $new_file = str_replace('.' . $info['extension'], '_thumb.' . $info['extension'], $file);
        return $func($dst, $folder . $new_file) ? $new_file : false;
    }
}
Exemple #5
0
function createthumb($img, $new_width, $new_height, $destpath)
{
    global $db;
    if (is_file($img)) {
        if ($cursize = getimagesize($img)) {
            $newsize = setWidthHeight($cursize[0], $cursize[1], $new_width, $new_height);
            $thepath = pathinfo($img);
            $dst = imagecreatetruecolor($newsize[0], $newsize[1]);
            $filename = str_replace("." . $thepath['extension'], "", $thepath["basename"]);
            $filename = $thepath["dirname"] . "/" . $destpath . "/" . $filename . "" . $size . "." . $thepath['extension'];
            $types = array('jpg' => array('imagecreatefromjpeg', 'imagejpeg'), 'jpeg' => array('imagecreatefromjpeg', 'imagejpeg'), 'gif' => array('imagecreatefromgif', 'imagegif'), 'png' => array('imagecreatefrompng', 'imagepng'));
            $x_type = strtolower($thepath['extension']);
            $func = $types[$x_type][0];
            $src = $func($img);
            imagecopyresampled($dst, $src, 0, 0, 0, 0, $newsize[0], $newsize[1], $cursize[0], $cursize[1]);
            $func = $types[$x_type][1];
            $func($dst, $filename);
            return $filename;
        }
    }
}