Example #1
1
 private function getImage()
 {
     $image = imagecreatefromstring(file_get_contents($this->file['tmp_name']));
     if ($this->currentExtension == 'jpg' || $this->currentExtension == 'jpeg') {
         $exif = exif_read_data($this->file['tmp_name']);
         if (!empty($exif['Orientation'])) {
             switch ($exif['Orientation']) {
                 case 8:
                     $image = imagerotate($image, 90, 0);
                     break;
                 case 3:
                     $image = imagerotate($image, 180, 0);
                     break;
                 case 6:
                     $image = imagerotate($image, -90, 0);
                     break;
             }
         }
     }
     // Get new sizes
     $width = imagesx($image);
     $height = imagesy($image);
     //list($width, $height) = getimagesize($this->file['tmp_name']);
     list($newWidth, $newHeight) = $this->getScaledDimArray($image, 800);
     // Load
     $resizeImage = imagecreatetruecolor($newWidth, $newHeight);
     // Resize
     imagecopyresized($resizeImage, $image, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
     return $resizeImage;
 }
Example #2
0
function addImage()
{
    global $db;
    $stmt = $db->prepare('INSERT INTO images VALUES(NULL)');
    $stmt->execute();
    $id = $db->lastInsertId();
    $originalFileName = "images/original/{$id}.jpg";
    $smallFileName = "images/thumbs_small/{$id}.jpg";
    $mediumFileName = "images/thumbs_medium/{$id}.jpg";
    move_uploaded_file($_FILES['image']['tmp_name'], $originalFileName);
    $original = imagecreatefromjpeg($originalFileName);
    $width = imagesx($original);
    $height = imagesy($original);
    $square = min($width, $height);
    $small = imagecreatetruecolor(200, 200);
    imagecopyresized($small, $original, 0, 0, $width > $square ? ($width - $square) / 2 : 0, $height > $square ? ($height - $square) / 2 : 0, 200, 200, $square, $square);
    imagejpeg($small, $smallFileName);
    $mediumwidth = $width;
    $mediumheight = $height;
    if ($mediumwidth > 400) {
        $mediumwidth = 400;
        $mediumheight = $mediumheight * ($mediumwidth / $width);
    }
    $medium = imagecreatetruecolor($mediumwidth, $mediumheight);
    imagecopyresized($medium, $original, 0, 0, 0, 0, $mediumwidth, $mediumheight, $width, $height);
    imagejpeg($medium, $mediumFileName);
    return $id;
}
Example #3
0
function embroidery2image($embroidery, $scale_post = 1, $scale_pre = false)
{
    // Create image
    $im = imagecreatetruecolor(ceil($embroidery->imageWidth * $scale_post), ceil($embroidery->imageHeight * $scale_post));
    imagesavealpha($im, true);
    imagealphablending($im, false);
    $color = imagecolorallocatealpha($im, 255, 255, 255, 127);
    imagefill($im, 0, 0, $color);
    // Draw stitches
    foreach ($embroidery->blocks as $block) {
        $color = imagecolorallocate($im, $block->color->r, $block->color->g, $block->color->b);
        $x = false;
        foreach ($block->stitches as $stitch) {
            if ($x !== false) {
                imageline($im, ($x - $embroidery->min->x) * $scale_post, ($y - $embroidery->min->y) * $scale_post, ($stitch->x - $embroidery->min->x) * $scale_post, ($stitch->y - $embroidery->min->y) * $scale_post, $color);
            }
            $x = $stitch->x;
            $y = $stitch->y;
        }
    }
    // Scale finished image
    if ($scale_pre) {
        $im2 = imagecreatetruecolor($embroidery->imageWidth * $scale_post * $scale_pre, $embroidery->imageHeight * $scale_post * $scale_pre);
        imagesavealpha($im2, true);
        imagealphablending($im2, false);
        imagecopyresized($im2, $im, 0, 0, 0, 0, $embroidery->imageWidth * $scale_post * $scale_pre, $embroidery->imageHeight * $scale_post * $scale_pre, $embroidery->imageWidth * $scale_post, $embroidery->imageHeight * $scale_post);
        imagedestroy($im);
        $im = $im2;
    }
    return $im;
}
Example #4
0
function create_thumbnail($filename)
{
    $percent = 0.1;
    list($width, $height) = getimagesize("/var/www/amberandbrice.com/workspace/images/" . $filename);
    $newwidth = $width * $percent;
    $newheight = $height * $percent;
    $thumb = imagecreatetruecolor($newwidth, $newheight);
    $ext = pathinfo($filename)['extension'];
    echo "<h1>{$ext}</h1>";
    switch ($ext) {
        case 'jpg':
        case 'jpeg':
        case 'JPG':
            $source = imagecreatefromjpeg("images/" . $filename);
            imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
            imagejpeg($thumb, "./thumbs/" . $filename);
            break;
        case 'gif':
            $source = imagecreatefromgif("images/" . $filename);
            imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
            imagejpeg($thumb, "./thumbs/" . $filename);
            break;
        case 'png':
            $source = imagecreatefrompng("images/" . $filename);
            imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
            imagejpeg($thumb, "./thumbs/" . $filename);
            break;
        default:
            die("image extension cannot be determined");
    }
}
Example #5
0
 /**
  * Automatically resizes an image and returns formatted IMG tag
  *
  * @param string $path Path to the image file, relative to the webroot/img/ directory.
  * @param integer $width Image of returned image
  * @param integer $height Height of returned image
  * @param boolean $aspect Maintain aspect ratio (default: true)
  * @param array	$htmlAttributes Array of HTML attributes.
  * @param boolean $return Wheter this method should return a value or output it. This overrides AUTO_OUTPUT.
  * @return mixed	Either string or echos the value, depends on AUTO_OUTPUT and $return.
  * @access public
  */
 public function resize($path, $width, $height, $aspect = true, $htmlAttributes = array(), $return = false)
 {
     $types = array(1 => "gif", "jpeg", "png", "swf", "psd", "wbmp");
     // used to determine image type
     if (empty($htmlAttributes['alt'])) {
         $htmlAttributes['alt'] = 'thumb';
     }
     // Ponemos alt default
     $uploadsDir = 'uploads';
     $fullpath = ROOT . DS . APP_DIR . DS . WEBROOT_DIR . DS . $uploadsDir . DS;
     $url = ROOT . DS . APP_DIR . DS . WEBROOT_DIR . DS . $path;
     if (!($size = getimagesize($url))) {
         return;
     }
     // image doesn't exist
     if ($aspect) {
         // adjust to aspect.
         if ($size[1] / $height > $size[0] / $width) {
             // $size[0]:width, [1]:height, [2]:type
             $width = ceil($size[0] / $size[1] * $height);
         } else {
             $height = ceil($width / ($size[0] / $size[1]));
         }
     }
     $relfile = $this->webroot . $uploadsDir . '/' . $this->cacheDir . '/' . $width . 'x' . $height . '_' . basename($path);
     // relative file
     $cachefile = $fullpath . $this->cacheDir . DS . $width . 'x' . $height . '_' . basename($path);
     // location on server
     if (file_exists($cachefile)) {
         $csize = getimagesize($cachefile);
         $cached = $csize[0] == $width && $csize[1] == $height;
         // image is cached
         if (@filemtime($cachefile) < @filemtime($url)) {
             // check if up to date
             $cached = false;
         }
     } else {
         $cached = false;
     }
     if (!$cached) {
         $resize = $size[0] > $width || $size[1] > $height || ($size[0] < $width || $size[1] < $height);
     } else {
         $resize = false;
     }
     if ($resize) {
         $image = call_user_func('imagecreatefrom' . $types[$size[2]], $url);
         if (function_exists("imagecreatetruecolor") && ($temp = imagecreatetruecolor($width, $height))) {
             imagecopyresampled($temp, $image, 0, 0, 0, 0, $width, $height, $size[0], $size[1]);
         } else {
             $temp = imagecreate($width, $height);
             imagecopyresized($temp, $image, 0, 0, 0, 0, $width, $height, $size[0], $size[1]);
         }
         call_user_func("image" . $types[$size[2]], $temp, $cachefile);
         imagedestroy($image);
         imagedestroy($temp);
     } else {
         //copy($url, $cachefile);
     }
     return $this->output(sprintf($this->Html->tags['image'], $relfile, $this->Html->_parseAttributes($htmlAttributes, null, '', ' ')), $return);
 }
Example #6
0
/**
*   @desc ������� ������ �����������
*   @return 
*/
function outputPreview($szContent, $szMime)
{
    $source = imagecreatefromstring($szContent);
    $nSourceHeight = imagesy($source);
    $nSourceWidth = imagesx($source);
    // �������� ������ � ������
    if (DAO_IMAGE_THUMBNAIL_X == 0) {
        $szHeight = DAO_IMAGE_THUMBNAIL_Y;
        $szWidth = intval($nSourceWidth * DAO_IMAGE_THUMBNAIL_Y / $nSourceHeight);
    } elseif (DAO_IMAGE_THUMBNAIL_Y == 0) {
        $szWidth = DAO_IMAGE_THUMBNAIL_X;
        $szHeight = intval($nSourceHeight * DAO_IMAGE_THUMBNAIL_X / $nSourceWidth);
    } else {
        $szWidth = DAO_IMAGE_THUMBNAIL_X;
        $szHeight = DAO_IMAGE_THUMBNAIL_Y;
    }
    $thumb = imagecreatetruecolor($szWidth, $szHeight);
    imagecopyresized($thumb, $source, 0, 0, 0, 0, $szWidth, $szHeight, $nSourceWidth, $nSourceHeight);
    switch ($szMime) {
        case 'image/jpeg':
            imagejpeg($thumb);
            break;
        case 'image/png':
            imagepng($thumb);
            break;
        case 'image/gif':
            imagegif($thumb);
            break;
        default:
            imagejpeg($thumb);
    }
}
function resize_image_gd($src, $dest, $quality, $width, $height, $image_info)
{
    global $convert_options;
    $types = array(1 => "gif", 2 => "jpeg", 3 => "png");
    if ($convert_options['convert_gd2']) {
        $thumb = imagecreatetruecolor($width, $height);
    } else {
        $thumb = imagecreate($width, $height);
    }
    $image_create_handle = "imagecreatefrom" . $types[$image_info[2]];
    if ($image = $image_create_handle($src)) {
        if ($convert_options['convert_gd2']) {
            imagecopyresampled($thumb, $image, 0, 0, 0, 0, $width, $height, ImageSX($image), ImageSY($image));
        } else {
            imagecopyresized($thumb, $image, 0, 0, 0, 0, $width, $height, ImageSX($image), ImageSY($image));
        }
        if ($image_info[2] == 3) {
            $quality = 9;
        }
        $image_handle = "image" . $types[$image_info[2]];
        $image_handle($thumb, $dest, $quality);
        imagedestroy($image);
        imagedestroy($thumb);
    }
    return file_exists($dest) ? 1 : 0;
}
Example #8
0
function crearThumbnail($uploaddir, $uploaddirthumbnails, $anchoImgThumbnail, $filename)
{
    if (preg_match('/[.](jpg)$/', $filename)) {
        $im = imagecreatefromjpeg($uploaddir . $filename);
    } else {
        if (preg_match('/[.](gif)$/', $filename)) {
            $im = imagecreatefromgif($uploaddir . $filename);
        } else {
            if (preg_match('/[.](png)$/', $filename)) {
                $im = imagecreatefrompng($uploaddir . $filename);
            }
        }
    }
    $ox = imagesx($im);
    // ancho de la imagen
    $oy = imagesy($im);
    // alto de la imagen
    $nx = $anchoImgThumbnail;
    $ny = floor($oy * ($anchoImgThumbnail / $ox));
    $nm = imagecreatetruecolor($nx, $ny);
    imagecopyresized($nm, $im, 0, 0, 0, 0, $nx, $ny, $ox, $oy);
    if (!file_exists($uploaddirthumbnails)) {
        if (!mkdir($uploaddirthumbnails)) {
            die("Hubo un problema al subir la foto.");
        }
    }
    imagejpeg($nm, $uploaddirthumbnails . $filename);
    return true;
}
Example #9
0
File: public.php Project: vvcumt/zk
/**
 * 压缩图像尺寸函数 imageresize
 * @perem $src_name 原始图像名称(包含路径名)
 * @perem $percent  压缩比例(如0.5为新图像宽高为原图一半)
 * @return $new_name 返回压缩后图像名称(包含路径名)
 * @caution:调用函数前请做好类型检查,尽限于gif、jpeg、jpg和png格式图像
 */
function img_resize($resize_percent, $src_file, $des_file)
{
    try {
        list($src_width, $src_height) = getimagesize($src_file);
        $new_width = $src_width * $resize_percent;
        $new_height = $src_height * $resize_percent;
        $new_image = imagecreatetruecolor($new_width, $new_height);
        $suff = strrchr($src_file, '.');
        switch ($suff) {
            case ".jpg":
            case ".jpeg":
                $src_image = imagecreatefromjpeg($src_file);
                imagecopyresized($new_image, $src_image, 0, 0, 0, 0, $new_width, $new_height, $src_width, $src_height);
                imagejpeg($new_image, $des_file, 75);
                break;
            case ".png":
                $src_image = imagecreatefrompng($src_file);
                imagecopyresized($new_image, $src_image, 0, 0, 0, 0, $new_width, $new_height, $src_width, $src_height);
                imagepng($new_image, $des_file);
                break;
            case ".gif":
                $src_image = imagecreatefromgif($src_file);
                imagecopyresized($new_image, $src_image, 0, 0, 0, 0, $new_width, $new_height, $src_width, $src_height);
                imagegif($new_image, $src_file);
                break;
            default:
                return false;
                break;
        }
    } catch (Exception $e) {
        Log::write("ImgResize::resize() exception: " . $e->getMessage(), "log");
        return false;
    }
    return true;
}
Example #10
0
 public function scale($dest, $width = null, $height = null, $force = false)
 {
     $im = $this->getIm();
     if (null === $width && null === $height) {
         $w = $width = imagesx($im);
         $h = $height = imagesy($im);
     } else {
         if (false === $force) {
             $w = imagesx($im);
             $h = imagesy($im);
             if (null === $width) {
                 $width = round($w * $height / $h);
             } else {
                 if (null === $height) {
                     $height = round($h * $width / $w);
                 } else {
                     if ($w / $h > $width / $height) {
                         $height = round($h * $width / $w);
                     } else {
                         $width = round($w * $height / $h);
                     }
                 }
             }
         }
     }
     if (function_exists("imagecreatetruecolor") && ($ni = imagecreatetruecolor($width, $height))) {
         imagecopyresampled($ni, $im, 0, 0, 0, 0, $width, $height, $w, $h);
     } else {
         $ni = imagecreate($width, $height);
         imagecopyresized($ni, $im, 0, 0, 0, 0, $width, $height, $w, $h);
     }
     imagejpeg($ni, $dest);
     ImageDestroy($ni);
 }
Example #11
0
function createthumb($name, $filename, $new_w, $new_h)
{
    // $src_img=null;
    //$system=explode(".",$name);
    if (preg_match("/jpg|jpeg|JPG/", $name)) {
        $src_img = imagecreatefromjpeg($name);
    }
    if (preg_match("/png/", $name)) {
        $src_img = imagecreatefrompng($name);
    }
    if (preg_match("/gif/", $name)) {
        $src_img = imagecreatefromgif($name);
    }
    $old_x = imagesX($src_img);
    $old_y = imagesY($src_img);
    $thumb_w = (int) $new_w;
    $thumb_h = (int) $new_h;
    //$dst_img=imagecreate($thumb_w,$thumb_h);
    $dst_img = imagecreatetruecolor($thumb_w, $thumb_h);
    //imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
    imagecopyresized($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y);
    if (preg_match("/png|PNG/", $name)) {
        imagepng($dst_img, $filename);
    } else {
        imagejpeg($dst_img, $filename, 100);
    }
    imagedestroy($dst_img);
    imagedestroy($src_img);
}
Example #12
0
/**
 * create thumbnail. will return false on failure.
 */
function create_thumbnail($picture, $picture_thumb, $w)
{
    // get src image
    if (pathinfo($picture, PATHINFO_EXTENSION) == "jpg") {
        $source_image = imagecreatefromjpeg($picture);
    } else {
        if (pathinfo($picture, PATHINFO_EXTENSION) == "png") {
            $source_image = imagecreatefrompng($picture);
        } else {
            return false;
        }
    }
    $width = imagesx($source_image);
    $height = imagesy($source_image);
    // calc height according to given width
    $h = floor($height * ($w / $width));
    // create virtual
    $virtual_image = imagecreatetruecolor($w, $h);
    // copy src image
    imagecopyresized($virtual_image, $source_image, 0, 0, 0, 0, $w, $h, $width, $height);
    // create thumbnail
    if (pathinfo($picture, PATHINFO_EXTENSION) == 'jpg') {
        imagejpeg($virtual_image, $picture_thumb, 83);
    } elseif (pathinfo($picture, PATHINFO_EXTENSION) == 'png') {
        imagepng($virtual_image, $picture_thumb);
    }
    return true;
}
function fastimagecopyresampled($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h, $quality = 3)
{
    // Plug-and-Play fastimagecopyresampled function replaces much slower imagecopyresampled.
    // Just include this function and change all "imagecopyresampled" references to "fastimagecopyresampled".
    // Typically from 30 to 60 times faster when reducing high resolution images down to thumbnail size using the default quality setting.
    // Author: Tim Eckel - Date: 12/17/04 - Project: FreeRingers.net - Freely distributable.
    //
    // Optional "quality" parameter (defaults is 3).  Fractional values are allowed, for example 1.5.
    // 1 = Up to 600 times faster.  Poor results, just uses imagecopyresized but removes black edges.
    // 2 = Up to 95 times faster.  Images may appear too sharp, some people may prefer it.
    // 3 = Up to 60 times faster.  Will give high quality smooth results very close to imagecopyresampled.
    // 4 = Up to 25 times faster.  Almost identical to imagecopyresampled for most images.
    // 5 = No speedup.  Just uses imagecopyresampled, highest quality but no advantage over imagecopyresampled.
    if (empty($src_image) || empty($dst_image)) {
        return false;
    }
    if ($quality <= 1) {
        $temp = imagecreatetruecolor($dst_w + 1, $dst_h + 1);
        imagecopyresized($temp, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w + 1, $dst_h + 1, $src_w, $src_h);
        imagecopyresized($dst_image, $temp, 0, 0, 0, 0, $dst_w, $dst_h, $dst_w, $dst_h);
        imagedestroy($temp);
    } elseif ($quality < 5 && ($dst_w * $quality < $src_w || $dst_h * $quality < $src_h)) {
        $tmp_w = $dst_w * $quality;
        $tmp_h = $dst_h * $quality;
        $temp = imagecreatetruecolor($tmp_w + 1, $tmp_h + 1);
        imagecopyresized($temp, $src_image, $dst_x * $quality, $dst_y * $quality, $src_x, $src_y, $tmp_w + 1, $tmp_h + 1, $src_w, $src_h);
        imagecopyresampled($dst_image, $temp, 0, 0, 0, 0, $dst_w, $dst_h, $tmp_w, $tmp_h);
        imagedestroy($temp);
    } else {
        imagecopyresampled($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
    }
    //return true;
}
Example #14
0
 /**
  * Get image hash
  * @param array $image
  * @return array
  */
 private function imagehex($image)
 {
     $size = getimagesize($image['path']);
     $func = 'imagecreatefrom'.$image['type'];
     $imageres = $func($image['path']);
     $zone = imagecreate(20, 20);
     imagecopyresized($zone, $imageres, 0, 0, 0, 0, 20, 20, $size[0], $size[1]);
     $colormap = array();
     $average = 0;
     $result = array();
     for($x=0; $x < 20; $x++)
     {
         for($y=0; $y < 20; $y++)
         {
             $color = imagecolorat($zone, $x, $y);
             $color = imagecolorsforindex($zone, $color);
             $colormap[$x][$y]= 0.212671 * $color['red'] + 0.715160 * $color['green'] + 0.072169 * $color['blue'];
             $average += $colormap[$x][$y];
         }
     }
     $average /= 400;
     for($x=0; $x < 20; $x++)
     {
         for($y=0; $y < 20; $y++)
         {
             $result[]=($x < 10 ? $x : chr($x+97)) . ($y < 10 ? $y : chr($y+97)) . ($colormap[$x][$y]==0 ? '0' : round(2*($colormap[$x][$y] > $average ? $colormap[$x][$y]/$average:-1*$average/$colormap[$x][$y])));
         }
     }
     return $result;
 }
Example #15
0
/**
 * Create a jpg thumbnail from images of type jpg, png or gif.
 *
 * @param string $src Path to the original file
 * @param string $ext Extension of the file
 * @param string $dest Path to the place to save the thumbnail
 * @param int $desired_width Width of the thumbnail (height is automatic depending on width)
 * @return null|false
 */
function make_thumb($src, $ext, $dest, $desired_width)
{
    // we don't want to work on too big images
    // put the limit to 5 Mbytes
    if (filesize($src) > 5000000) {
        return false;
    }
    // the used fonction is different depending on extension
    if (preg_match('/(jpg|jpeg)$/i', $ext)) {
        $source_image = imagecreatefromjpeg($src);
    } elseif (preg_match('/(png)$/i', $ext)) {
        $source_image = imagecreatefrompng($src);
    } elseif (preg_match('/(gif)$/i', $ext)) {
        $source_image = imagecreatefromgif($src);
    } else {
        return false;
    }
    $width = imagesx($source_image);
    $height = imagesy($source_image);
    // find the "desired height" of this thumbnail, relative to the desired width
    $desired_height = floor($height * ($desired_width / $width));
    // create a new, "virtual" image
    $virtual_image = imagecreatetruecolor($desired_width, $desired_height);
    // copy source image at a resized size
    imagecopyresized($virtual_image, $source_image, 0, 0, 0, 0, $desired_width, $desired_height, $width, $height);
    // create the physical thumbnail image to its destination (85% quality)
    imagejpeg($virtual_image, $dest, 85);
}
Example #16
0
function createThumbs($pathToImages, $pathToThumbs, $thumbWidth)
{
    // open the directory
    $dir = opendir($pathToImages);
    // loop through it, looking for any/all JPG files:
    while (false !== ($fname = readdir($dir))) {
        // parse path for the extension
        $info = pathinfo($pathToImages . $fname);
        // continue only if this is a JPEG image
        if (strtolower($info['extension']) == 'jpg') {
            echo "Creating thumbnail for {$fname} <br />";
            // load image and get image size
            $img = imagecreatefromjpeg("{$pathToImages}{$fname}");
            $width = imagesx($img);
            $height = imagesy($img);
            // calculate thumbnail size
            $new_width = $thumbWidth;
            $new_height = floor($height * ($thumbWidth / $width));
            // create a new temporary image
            $tmp_img = imagecreatetruecolor($new_width, $new_height);
            // copy and resize old image into new image
            imagecopyresized($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
            // save thumbnail into a file
            imagejpeg($tmp_img, "{$pathToThumbs}{$fname}", 100);
            $pic_data = 'ORG: H:' . $height . ' W: ' . $width . '<br> NEW: H:' . $new_height . ' W: ' . $new_width . '<br><br>';
            echo $pic_data;
        }
    }
    // close the directory
    closedir($dir);
}
Example #17
0
	public function makeMapSheetAction() {
		// Set up config options
		$sourceSize = 16;
		$destinationSize = 32;
		
		$images = array();
		
		$dir = $_SERVER['DOCUMENT_ROOT'] . '/modules/wes/img/sprites/maps/jidoor-tiles';
		$writeDir = $_SERVER['DOCUMENT_ROOT'] . '/modules/wes/img/sprites/maps';
		if ($handle = opendir($dir)) {
			while (false !== ($file = readdir($handle))) {
				if ($file != "." && $file != "..") {
					$images[] = $dir . '/' . $file;
				}
			}
			closedir($handle);
		}
		
		$numTiles = count($images);
		$tileSheet = imagecreatetruecolor($numTiles * $destinationSize, $destinationSize);
		
		for ($i = 0; $i < $numTiles; $i++) {
			$tile = imagecreatefrompng($images[$i]);
			$x = $i * $destinationSize;
			$y = 0;
			imagecopyresized($tileSheet, $tile, $x, $y, 0, 0, $destinationSize, $destinationSize, $sourceSize, $sourceSize);
			imagedestroy($tile);
		}
		
		imagepng($tileSheet, $writeDir . '/sheet.png');
		imagedestroy($tileSheet);
		
		show_array($images);
		die();
	}
/**
 * A function which splits a jpg image into smaller pieces (kind of like a jigsaw) and uploads those images to the
 * WordPress uploads folder.
 *
 * @param $jpeg_path : path to the jpg to split
 * @param $width : width of the required output images
 * @param @height : height of the required output images
 *
 * @return an array of paths to the image parts created (or false if it all goes horribly wrong)
 *
 * @package Friendly Split Image
 * @author iamfriendly
 * @version 1.0
 * @since 1.0
 */
function friendly_wp_split_image($jpeg_path = false, $width = 100, $height = 100)
{
    if ($jpeg_path === false) {
        return false;
    }
    $source = @imagecreatefromjpeg($jpeg_path);
    $source_width = imagesx($source);
    $source_height = imagesy($source);
    $upload_dir = wp_upload_dir();
    $upload_path = $upload_dir['path'];
    $img_parts = array();
    for ($col = 0; $col < $source_width / $width; $col++) {
        for ($row = 0; $row < $source_height / $height; $row++) {
            $fn = sprintf("img%02d_%02d.jpg", $col, $row);
            $col_class = $col + 1;
            $row_class = $row + 1;
            array_push($img_parts, $fn);
            $im = @imagecreatetruecolor($width, $height);
            imagecopyresized($im, $source, 0, 0, $col * $width, $row * $height, $width, $height, $width, $height);
            imagejpeg($im, $fn);
            imagedestroy($im);
        }
    }
    return $img_parts;
}
function generateAvatarGD($gdversion, $src_img, $srcWidth, $srcHeight, $dstWidth, $dstHeight, $quality, $location)
{
    if ($srcWidth > $dstWidth || $srcHeight > $dstHeight) {
        $ratio = $srcWidth / $srcHeight;
        if ($dstWidth / $dstHeight > $ratio) {
            $dstWidth = $dstHeight * $ratio;
        } else {
            $dstHeight = $dstWidth / $ratio;
        }
    } else {
        $dstWidth = $srcWidth;
        $dstHeight = $srcHeight;
    }
    if ((int) $gdversion == 1) {
        $dst_img = imagecreate($dstWidth, $dstHeight);
        imagecopyresized($dst_img, $src_img, 0, 0, 0, 0, (int) $dstWidth, (int) $dstHeight, $srcWidth, $srcHeight);
    } else {
        $dst_img = imagecreatetruecolor($dstWidth, $dstHeight);
        imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, (int) $dstWidth, (int) $dstHeight, $srcWidth, $srcHeight);
    }
    $tmpfile = tempnam(CKunenaPath::tmpdir(), "kn_");
    imagejpeg($dst_img, $tmpfile, $quality);
    CKunenaFile::copy($tmpfile, $location);
    unlink($tmpfile);
    imagedestroy($dst_img);
}
Example #20
0
 function resize($width = NULL, $height = NULL)
 {
     if (!$height && $width > 0) {
         $newWidth = $width;
         $newHeight = round($width / $this->width * $this->height);
     } elseif (!$width && $height > 0) {
         $newHeight = $height;
         $newWidth = round($height / $this->height * $this->width);
     } elseif ($width > 0 && $height > 0) {
         $newHeight = $height;
         $newWidth = $width;
     } else {
         return false;
     }
     $newimg = imagecreatetruecolor($newWidth, $newHeight);
     if (function_exists('imagecopyresampled')) {
         imagecopyresampled($newimg, $this->image, 0, 0, 0, 0, $newWidth, $newHeight, $this->width, $this->height);
     } else {
         imagecopyresized($newimg, $this->image, 0, 0, 0, 0, $newWidth, $newHeight, $this->width, $this->height);
     }
     $this->width = $newWidth;
     $this->height = $newHeight;
     imagedestroy($this->image);
     $this->image = $newimg;
     return true;
 }
Example #21
0
 public function getLogo()
 {
     $f_info = pathinfo($this->url_logo);
     $get_w = $this->input->get('w');
     $get_h = $this->input->get('h');
     // Get new sizes
     list($width, $height) = getimagesize($this->url_logo);
     $newwidth = $get_w === FALSE ? $this->size_x : $get_w;
     $newheight = $get_h === FALSE ? $this->size_y : $get_h;
     $thumb = imagecreatetruecolor($newwidth, $newheight);
     //compress picture size
     if (strtolower($f_info['extension']) == 'jpg') {
         $image = imagecreatefromjpeg($this->url_logo);
         $call = 'imagejpeg';
         $content = 'image/jpeg';
     }
     if (strtolower($f_info['extension']) == 'png') {
         $image = imagecreatefrompng($this->url_logo);
         $call = 'imagepng';
         $content = 'image/jpeg';
     }
     if (strtolower($f_info['extension']) == 'gif') {
         $image = imagecreatefromgif($this->url_logo);
         $call = 'imagegif';
         $content = 'image/gif';
     }
     @header('Content-Type : ' . $content);
     imagecopyresized($thumb, $image, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
     call_user_func($call, $thumb);
     imagedestroy($thumb);
 }
Example #22
0
 public function getBarcodeFilePath()
 {
     $stu = $this;
     $filename = sfConfig::get('sf_root_dir') . '/' . sfConfig::get('sf_app') . '/images/tmp/stu_' . $stu->getCode() . '.png';
     $url_filename = sfContext::getInstance()->getRequest()->getRelativeUrlRoot() . '/images/tmp/';
     define('IMG_FORMAT_PNG', 1);
     define('IMG_FORMAT_JPEG', 2);
     define('IMG_FORMAT_WBMP', 4);
     define('IMG_FORMAT_GIF', 8);
     require_once 'FColor.php';
     require_once 'BarCode.php';
     require_once 'FDrawing.php';
     include_once 'code128.barcode.php';
     $color_black = new FColor(0, 0, 0);
     $color_white = new FColor(255, 255, 255);
     /* Here is the list of the arguments:
     		1 - Thickness
     		2 - Color of bars
     		3 - Color of spaces
     		4 - Resolution
     		5 - Text
     		6 - Text Font (or 0) */
     $code_generated = new code128(40, $color_black, $color_white, 2, $stu->getCode(), 0);
     $drawing = new FDrawing(1024, 1024, $filename, $color_white);
     $drawing->init();
     $drawing->add_barcode($code_generated);
     $drawing->draw_all();
     $im = $drawing->get_im();
     $im2 = imagecreate($code_generated->lastX, $code_generated->lastY);
     imagecopyresized($im2, $im, 0, 0, 0, 0, $code_generated->lastX, $code_generated->lastY, $code_generated->lastX, $code_generated->lastY);
     $drawing->set_im($im2);
     $drawing->finish(1);
     return $url_filename . 'stu_' . $this->getCode() . '.png';
 }
Example #23
0
function resize_image($pathToImages, $pathToThumbs, $thumbWidth)
{
    // open the directory
    $dir = opendir($pathToImages);
    // loop through it, looking for any/all JPG files:
    while (false !== ($fname = readdir($dir))) {
        // parse path for the extension
        $info = pathinfo($pathToImages . $fname);
        // continue only if this is a JPEG image
        if (strtolower($info['extension']) == 'jpg' && $fname != "thumb.jpg") {
            // load image and get image size
            $img = imagecreatefromjpeg("{$pathToImages}" . "/" . "{$fname}");
            $width = imagesx($img);
            $height = imagesy($img);
            // calculate thumbnail size
            $new_width = $thumbWidth;
            $new_height = floor($height * ($thumbWidth / $width));
            // create a new temporary image
            $tmp_img = imagecreatetruecolor($new_width, $new_height);
            // copy and resize old image into new image
            imagecopyresized($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
            // save thumbnail into a file
            imagejpeg($tmp_img, "{$pathToThumbs}" . "/" . "{$fname}");
            echo "Se redujo la imagen  {$fname} <br />";
            //echo "$pathToThumbs" . "/" . "$fname<br/>";
        }
    }
    // close the directory
    closedir($dir);
}
function resize_image($src, $dest, $src_h, $src_w, $dest_h, $dest_w, $type, $src_x=0, $src_y=0) {
	$thumbnail_img = imagecreatetruecolor($dest_w, $dest_h);

	if ($type == 'gif') {
		$source = imagecreatefromgif($src);
	} else if ($type == 'jpg') {
		$source = imagecreatefromjpeg($src);
	} else {
		$source = imagecreatefrompng($src);
	}
	
	if ($src_x > 0 || $src_y > 0){
		imagecopyresized($thumbnail_img, $source, 0, 0, $src_x, $src_y, $dest_w, $dest_h, $src_w, $src_h);
	} else {
		imagecopyresampled($thumbnail_img, $source, $src_x, $src_y, 0, 0, $dest_w, $dest_h, $src_w, $src_h);
	}

	if ($type == 'gif') {
		imagegif($thumbnail_img, $dest);
	} else if ($type == 'jpg') {
		imagejpeg($thumbnail_img, $dest, 75);
	} else {
		imagepng($thumbnail_img, $dest, 7);
	}
}
Example #25
0
function fastimagecopyresampled($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h, $quality = 3)
{
    // Plug-and-Play fastimagecopyresampled function replaces much slower imagecopyresampled.
    // Just include this function and change all "imagecopyresampled" references to "fastimagecopyresampled".
    // Typically from 30 to 60 times faster when reducing high resolution images down to thumbnail size using the default quality setting.
    // Author: Tim Eckel - Date: 09/07/07 - Version: 1.1 - Project: FreeRingers.net - Freely distributable - These comments must remain.
    //
    // Optional "quality" parameter (defaults is 3). Fractional values are allowed, for example
    // 1.5. Must be greater than zero.
    // Between 0 and 1 = Fast, but mosaic results, closer to 0 increases the mosaic effect.
    // 1 = Up to 350 times faster. Poor results, looks very similar to imagecopyresized.
    // 2 = Up to 95 times faster.  Images appear a little sharp, some prefer this over a quality of 3.
    // 3 = Up to 60 times faster.  Will give high quality smooth results very close to imagecopyresampled, just faster.
    // 4 = Up to 25 times faster.  Almost identical to imagecopyresampled for most images.
    // 5 = No speedup. Just uses imagecopyresampled, no advantage over imagecopyresampled.
    if (empty($src_image) || empty($dst_image) || $quality <= 0) {
        return false;
    }
    if ($quality < 5 && ($dst_w * $quality < $src_w || $dst_h * $quality < $src_h)) {
        $temp = imagecreatetruecolor($dst_w * $quality + 1, $dst_h * $quality + 1);
        imagecopyresized($temp, $src_image, 0, 0, $src_x, $src_y, $dst_w * $quality + 1, $dst_h * $quality + 1, $src_w, $src_h);
        imagecopyresampled($dst_image, $temp, $dst_x, $dst_y, 0, 0, $dst_w, $dst_h, $dst_w * $quality, $dst_h * $quality);
        imagedestroy($temp);
    } else {
        imagecopyresampled($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
    }
    return true;
}
Example #26
0
 public static function resize($path, $width, $height)
 {
     $new_image = imagecreatetruecolor($width, $height);
     $src = imagecreatefromjpeg($path);
     imagecopyresized($new_image, $src, 0, 0, 0, 0, $width, $height, imagesx($path), imagesy($path));
     imagejpg($new_image);
 }
Example #27
0
 private function createnewpicture()
 {
     $local = $this->path_two . $this->file['name'];
     move_uploaded_file($this->file['tmp_name'], $local);
     $filename = $this->file['tmp_name'] . "/" . $this->file['name'];
     $this->location = $this->path . "/" . $this->file['name'];
     switch ($this->file['type']) {
         case 'image/jpeg':
             $src = imagecreatefromjpeg($local);
             break;
         case 'image/png':
             $src = imagecreatefrompng($local);
             break;
         case 'image/gif':
             $src = imagecreatefromgif($local);
             break;
         default:
             break;
     }
     $sx = imagesx($src);
     $sy = imagesy($src);
     $new_image = imagecreatetruecolor($this->newwidth, $this->newheight);
     if (imagecopyresized($new_image, $src, 0, 0, 0, 0, $this->newwidth, $this->newheight, $sx, $sy)) {
         if (ImageJpeg($new_image, $this->location) || Imagegif($new_image, $this->location) || Imagepng($new_image, $this->location)) {
             //imagejpeg($this->location);
             return true;
         }
     } else {
         return false;
     }
 }
Example #28
0
function setImage($x, $y, $image)
{
    global $bcg, $wsp;
    $part_image = getimagesize($image);
    if ($part_image['mime'] == 'image/jpeg') {
        $img = imagecreatefromjpeg($image);
    }
    if ($part_image['mime'] == 'image/gif') {
        $img = imagecreatefromgif($image);
    }
    if ($part_image['mime'] == 'image/png') {
        $img = imagecreatefrompng($image);
    }
    list($img_width, $img_height) = $part_image;
    $img_new_width = $img_width * $wsp;
    $img_new_height = $img_height * $wsp;
    $thumb = imagecreatetruecolor($img_new_width, $img_new_height);
    imagecopyresized($thumb, $img, 0, 0, 0, 0, $img_new_width, $img_new_height, $img_width, $img_height);
    imagecopymerge($bcg, $thumb, $x * $wsp, $y * $wsp, 0, 0, imagesx($thumb), imagesy($thumb), 100);
    $black = imagecolorallocate($bcg, 0, 0, 0);
    /*		LEFT	*/
    imageBoldLine($bcg, $x * $wsp, $y * $wsp, $x * $wsp, $y * $wsp + imagesy($thumb), $black, 2);
    /*		TOP	*/
    imageBoldLine($bcg, $x * $wsp, $y * $wsp, $x * $wsp + imagesx($thumb), $y * $wsp, $black, 2);
    /*		BOTTOM	*/
    imageBoldLine($bcg, $x * $wsp, $y * $wsp + imagesy($thumb), $x * $wsp + imagesx($thumb), $y * $wsp + imagesy($thumb), $black, 2);
    /*		RIGHT	*/
    imageBoldLine($bcg, $x * $wsp + imagesx($thumb), $y * $wsp, $x * $wsp + imagesx($thumb), $y * $wsp + imagesy($thumb), $black, 2);
}
Example #29
0
 public static function createThumbnail($filename, $path_to_image_directory, $path_to_thumbs_directory, $final_width_of_image)
 {
     if (preg_match('/[.](jpg)$/', $filename)) {
         $im = imagecreatefromjpeg($path_to_image_directory . $filename);
     } else {
         if (preg_match('/[.](gif)$/', $filename)) {
             $im = imagecreatefromgif($path_to_image_directory . $filename);
         } else {
             if (preg_match('/[.](png)$/', $filename)) {
                 $im = imagecreatefrompng($path_to_image_directory . $filename);
             }
         }
     }
     $ox = imagesx($im);
     $oy = imagesy($im);
     $nx = $final_width_of_image;
     $ny = floor($oy * ($final_width_of_image / $ox));
     $nm = imagecreatetruecolor($nx, $ny);
     imagecopyresized($nm, $im, 0, 0, 0, 0, $nx, $ny, $ox, $oy);
     if (!file_exists($path_to_thumbs_directory)) {
         if (!mkdir($path_to_thumbs_directory)) {
             die("There was a problem. Please try again!");
         }
     }
     imagejpeg($nm, $path_to_thumbs_directory . $filename);
     // $tn = '<img src="' . $path_to_thumbs_directory . $filename . '" alt="image" />';
     // $tn .= '<br />Congratulations. Your file has been successfully uploaded, and a      thumbnail has been created.';
     // echo $tn;
 }
Example #30
-1
 function output()
 {
     $arr = $this->ret;
     $bg = DATA_DIR . '/cache/vcodebg.png';
     $image = imagecreatefrompng($bg);
     list($w, $baseH) = getimagesize($bg);
     header('Content-type: image/png');
     $x = 1;
     foreach ($arr as $i => $filename) {
         list($w, $h) = getimagesize($filename);
         $source = imagecreatefrompng($filename);
         $t_id = imagecolortransparent($source);
         $rotate = imagerotate($source, rand(-20, 20), $t_id);
         $w2 = $w * $baseH / $h;
         imagecopyresized($image, $rotate, $x, 0, 0, 0, $w2, $baseH, $w, $h);
         imagedestroy($source);
         imagedestroy($rotate);
         $x += $w2;
     }
     $x += 1;
     $dst = imagecreatetruecolor($x, $baseH);
     imagecopyresampled($dst, $image, 0, 0, 0, 0, $x, $baseH, $x, $baseH);
     imagepng($dst);
     imagedestroy($image);
     imagedestroy($dst);
     exit;
 }