Example #1
2
function kicsinyites($forras, $kimenet, $max)
{
    if (!isset($max)) {
        $max = 120;
    }
    # maximum size of 1 side of the picture.
    $src_img = ImagecreateFromJpeg($forras);
    $oh = imagesy($src_img);
    # original height
    $ow = imagesx($src_img);
    # original width
    $new_h = $oh;
    $new_w = $ow;
    if ($oh > $max || $ow > $max) {
        $r = $oh / $ow;
        $new_h = $oh > $ow ? $max : $max * $r;
        $new_w = $new_h / $r;
    }
    // note TrueColor does 256 and not.. 8
    $dst_img = ImageCreateTrueColor($new_w, $new_h);
    /* imageantialias($dst_img, true); */
    /* ImageCopyResized($dst_img, $src_img, 0,0,0,0, $new_w, $new_h, ImageSX($src_img), ImageSY($src_img)); */
    ImageCopyResampled($dst_img, $src_img, 0, 0, 0, 0, $new_w, $new_h, ImageSX($src_img), ImageSY($src_img));
    ImageJpeg($dst_img, "{$kimenet}");
}
 static function newGalleryImage($image)
 {
     # Grab filename and image type from upload
     $file_ext = self::$imageTypes[$image['type']];
     $filename = $image['name'];
     # Upload of image
     copy($image['tmp_name'], "gallery_images/" . $filename);
     # Grabs file suffix for variable function calls
     $function_suffix = strtoupper($file_ext);
     # Variable read/write functions for image creation
     $function_to_read = 'ImageCreateFrom' . $function_suffix;
     $function_to_write = 'Image' . $function_suffix;
     # Determine the file size and create a proportionally sized thumbnail
     $size = GetImageSize("gallery_images/" . $filename);
     if ($size[0] > $size[1]) {
         $thumbnail_width = 200;
         $thumbnail_height = (int) (200 * $size[1] / $size[0]);
     } else {
         $thumbnail_width = (int) (200 * $size[0] / $size[1]);
         $thumbnail_height = 200;
     }
     $source_handle = $function_to_read("gallery_images/" . $filename);
     if ($source_handle) {
         $destination_handle = ImageCreateTrueColor($thumbnail_width, $thumbnail_height);
         ImageCopyResampled($destination_handle, $source_handle, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $size[0], $size[1]);
     }
     $function_to_write($destination_handle, "gallery_images/tb/" . $filename);
 }
 public function update_picture()
 {
     if (trim($_FILES["myfile"]["tmp_name"]) != "") {
         $images = $_FILES["myfile"]["tmp_name"];
         $new_images = "thumb_" . $this->session->userdata('std_cardid') . '_' . $_FILES["myfile"]["name"];
         copy($_FILES["myfile"]["tmp_name"], "assets/uploads/photo/" . $_FILES["myfile"]["name"]);
         $width = 150;
         //*** Fix Width & Heigh (Autu caculate) ***//
         $size = GetimageSize($images);
         $height = round($width * $size[1] / $size[0]);
         $images_orig = ImageCreateFromJPEG($images);
         $photoX = ImagesX($images_orig);
         $photoY = ImagesY($images_orig);
         $images_fin = ImageCreateTrueColor($width, $height);
         ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width + 1, $height + 1, $photoX, $photoY);
         ImageJPEG($images_fin, "assets/uploads/photo/" . $new_images);
         ImageDestroy($images_orig);
         ImageDestroy($images_fin);
     }
     $fileName = $_FILES["myfile"]["name"];
     $ret[] = $fileName;
     $data_picture = array('std_picture' => $new_images);
     $this->Students_model->update_student_picture($this->session->userdata('std_cardid'), $data_picture);
     //echo  base_url()."assets/uploads/photo/".$new_images;
     redirect('/front_profiles/student_edit', 'refresh');
     //ChromePhp::log($ret);
     //exit;
 }
Example #4
0
 public function resize($width, $height)
 {
     $type = exif_imagetype($this->image);
     if ($type == 2) {
         $images_orig = ImageCreateFromJPEG($this->image);
     } elseif ($type == 3) {
         $images_orig = ImageCreateFromPNG($this->image);
     } elseif ($type == 1) {
         $images_orig = ImageCreateFromGIF($this->image);
     } else {
         return false;
     }
     $photoX = ImagesX($images_orig);
     $photoY = ImagesY($images_orig);
     $images_fin = ImageCreateTrueColor($width, $height);
     ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width + 1, $height + 1, $photoX, $photoY);
     if ($type == 2) {
         ImageJPEG($images_fin, $this->image);
     } elseif ($type == 3) {
         ImagePNG($images_fin, $this->image);
     } elseif ($type == 1) {
         ImageGIF($images_fin, $this->image);
     }
     ImageDestroy($images_orig);
     ImageDestroy($images_fin);
     return true;
 }
function image_resize_greyscale(&$src_im)
{
    $src_x = ceil(imagesx($src_im));
    $src_y = ceil(imagesy($src_im));
    $dst_x = $src_x;
    $dst_y = $src_y;
    // http://php.about.com/od/gdlibrary/ss/grayscale_gd.htm
    function yiq($r, $g, $b)
    {
        return $r * 0.299 + $g * 0.587 + $b * 0.114;
    }
    $dst_im = ImageCreateTrueColor($dst_x, $dst_y);
    ImageCopyResampled($dst_im, $src_im, 0, 0, 0, 0, $dst_x, $dst_y, $src_x, $src_y);
    for ($c = 0; $c < 256; $c++) {
        $palette[$c] = imagecolorallocate($dst_im, $c, $c, $c);
    }
    for ($y = 0; $y < $src_y; $y++) {
        for ($x = 0; $x < $src_x; $x++) {
            $rgb = imagecolorat($dst_im, $x, $y);
            $r = $rgb >> 16 & 0xff;
            $g = $rgb >> 8 & 0xff;
            $b = $rgb & 0xff;
            $gs = yiq($r, $g, $b);
            imagesetpixel($dst_im, $x, $y, $palette[$gs]);
        }
    }
    $src_im = $dst_im;
}
Example #6
0
 private function resizeImage($file, $data, $tmd = 600, $quality = 100)
 {
     $data['type'] = "image/jpeg";
     $basename = basename($file);
     $filesDir = $this->input->post('uploadDir');
     // хэш нередактируемой карты!
     $uploaddir = implode(array($this->input->server('DOCUMENT_ROOT'), 'storage', $tmd, $filesDir), DIRECTORY_SEPARATOR);
     $srcFile = implode(array($this->input->server('DOCUMENT_ROOT'), 'storage', 'source', $filesDir, $basename), DIRECTORY_SEPARATOR);
     $image = $this->createimageByType($data, $srcFile);
     if (!file_exists($uploaddir)) {
         mkdir($uploaddir, 0775, true);
     }
     $size = GetImageSize($srcFile);
     $new = ImageCreateTrueColor($size['1'], $size['0']);
     if ($size['1'] > $tmd || $size['0'] > $tmd) {
         if ($size['1'] < $size['0']) {
             $hNew = round($tmd * $size['1'] / $size['0']);
             $new = ImageCreateTrueColor($tmd, $hNew);
             ImageCopyResampled($new, $image, 0, 0, 0, 0, $tmd, $hNew, $size['0'], $size['1']);
         }
         if ($size['1'] >= $size['0']) {
             $hNew = round($tmd * $size['0'] / $size['1']);
             $new = ImageCreateTrueColor($hNew, $tmd);
             ImageCopyResampled($new, $image, 0, 0, 0, 0, $hNew, $tmd, $size['0'], $size['1']);
         }
     }
     //print $uploaddir."/".TMD."/".$filename.".jpg<br>";
     imageJpeg($new, $uploaddir . DIRECTORY_SEPARATOR . $basename, $quality);
     //header("content-type: image/jpeg");// активировать для отладки
     //imageJpeg ($new, "", 100);//активировать для отладки
     imageDestroy($new);
 }
 function execute()
 {
     $gdimage =& $this->image->getImage();
     $w = $this->image->getWidth();
     $h = $this->image->getHeight();
     $src_x = ceil($w);
     $src_y = ceil($h);
     $dst_x = $src_x;
     $dst_y = $src_y;
     // http://php.about.com/od/gdlibrary/ss/grayscale_gd.htm
     function yiq($r, $g, $b)
     {
         return $r * 0.299 + $g * 0.587 + $b * 0.114;
     }
     $dst_im = ImageCreateTrueColor($dst_x, $dst_y);
     ImageCopyResampled($dst_im, $gdimage, 0, 0, 0, 0, $dst_x, $dst_y, $src_x, $src_y);
     for ($c = 0; $c < 256; $c++) {
         $palette[$c] = imagecolorallocate($dst_im, $c, $c, $c);
     }
     for ($y = 0; $y < $src_y; $y++) {
         for ($x = 0; $x < $src_x; $x++) {
             $rgb = imagecolorat($dst_im, $x, $y);
             $r = $rgb >> 16 & 0xff;
             $g = $rgb >> 8 & 0xff;
             $b = $rgb & 0xff;
             $gs = yiq($r, $g, $b);
             imagesetpixel($dst_im, $x, $y, $palette[$gs]);
         }
     }
     $gdimage = $dst_im;
 }
 function execute()
 {
     if (!$this->image->isImage()) {
         return false;
     }
     $gdimage =& $this->image->getImage();
     $w = $this->image->getWidth();
     $h = $this->image->getHeight();
     $src_x = ceil($w);
     $src_y = ceil($h);
     $dst_x = $src_x;
     $dst_y = $src_y;
     $dst_im = ImageCreateTrueColor($dst_x, $dst_y);
     ImageCopyResampled($dst_im, $gdimage, 0, 0, 0, 0, $dst_x, $dst_y, $src_x, $src_y);
     for ($c = 0; $c < 256; $c++) {
         $palette[$c] = imagecolorallocate($dst_im, $c, $c, $c);
     }
     for ($y = 0; $y < $src_y; $y++) {
         for ($x = 0; $x < $src_x; $x++) {
             $rgb = imagecolorat($dst_im, $x, $y);
             $r = $rgb >> 16 & 0xff;
             $g = $rgb >> 8 & 0xff;
             $b = $rgb & 0xff;
             $gs = $r * 0.299 + $g * 0.587 + $b * 0.114;
             imagesetpixel($dst_im, $x, $y, $palette[$gs]);
         }
     }
     $gdimage = $dst_im;
 }
Example #9
0
 function resize($newX = false, $newY = false)
 {
     if ($this->img) {
         $X = ImageSX($this->img);
         $Y = ImageSY($this->img);
         $newX = $this->_convert($newX, $X);
         $newY = $this->_convert($newY, $Y);
         if (!$newX && !$newY) {
             $newX = $X;
             $newY = $Y;
         }
         if (!$newX) {
             $newX = round($X / ($Y / $newY));
         }
         if (!$newY) {
             $newY = round($Y / ($X / $newX));
         }
         if (!($newimg = ImageCreateTruecolor($newX, $newY))) {
             $newimg = ImageCreate($newX, $newY);
         }
         if (!ImageCopyResampled($newimg, $this->img, 0, 0, 0, 0, $newX, $newY, $X, $Y)) {
             ImageCopyResized($newimg, $this->img, 0, 0, 0, 0, $newX, $newY, $X, $Y);
         }
         $this->img = $newimg;
         return true;
     } else {
         return false;
     }
 }
Example #10
0
function thumb($filename, $x, $y = 0)
{
    $t = getimagesize($filename) or die('Illegal type');
    $with = $t[0];
    $height = $t[1];
    switch ($t[2]) {
        case 1:
            $type = 'GIF';
            $img = imagecreatefromgif($filename);
            break;
        case 2:
            $type = 'JPEG';
            $img = imagecreatefromjpeg($filename);
            break;
        case 3:
            $type = 'PNG';
            $img = imagecreatefrompng($filename);
            break;
    }
    if ($y == 0) {
        $y = $x * ($height / $with);
    }
    header("Content-type: image/jpeg");
    $thumb = imagecreatetruecolor($x, $y);
    ImageCopyResampled($thumb, $img, 0, 0, 0, 0, $x, $y, $with, $height);
    $thumb = imagejpeg($thumb);
    return $thumb;
}
Example #11
0
 public function crop($x, $y, $w, $h)
 {
     $this->sourceImageResoc = imagecreatefromjpeg($this->path . $this->name . '.' . $this->extension);
     $this->destinationImageResoc = ImageCreateTrueColor($w, $h);
     ImageCopyResampled($this->destinationImageResoc, $this->sourceImageResoc, 0, 0, $x, $y, $w, $h, $w, $h);
     return $this;
 }
Example #12
0
 public function saveImg($path)
 {
     // Resize
     if ($this->resize) {
         $this->output = ImageCreateTrueColor($this->xOutput, $this->yOutput);
         ImageCopyResampled($this->output, $this->input, 0, 0, 0, 0, $this->xOutput, $this->yOutput, $this->xInput, $this->yInput);
     }
     // Save JPEG
     if ($this->format == "JPG" or $this->format == "JPEG") {
         if ($this->resize) {
             imageJPEG($this->output, $path, $this->quality);
         } else {
             copy($this->src, $path);
         }
     } elseif ($this->format == "PNG") {
         if ($this->resize) {
             imagePNG($this->output, $path);
         } else {
             copy($this->src, $path);
         }
     } elseif ($this->format == "GIF") {
         if ($this->resize) {
             imageGIF($this->output, $path);
         } else {
             copy($this->src, $path);
         }
     }
 }
Example #13
0
 public function execute()
 {
     $this->media->asImage();
     $gdimage = $this->media->getImage();
     $w = $this->media->getWidth();
     $h = $this->media->getHeight();
     $src_x = ceil($w);
     $src_y = ceil($h);
     $dst_x = $src_x;
     $dst_y = $src_y;
     $dst_im = ImageCreateTrueColor($dst_x, $dst_y);
     ImageCopyResampled($dst_im, $gdimage, 0, 0, 0, 0, $dst_x, $dst_y, $src_x, $src_y);
     for ($c = 0; $c < 256; ++$c) {
         $palette[$c] = imagecolorallocate($dst_im, $c, $c, $c);
     }
     for ($y = 0; $y < $src_y; ++$y) {
         for ($x = 0; $x < $src_x; ++$x) {
             $rgb = imagecolorat($dst_im, $x, $y);
             $r = $rgb >> 16 & 0xff;
             $g = $rgb >> 8 & 0xff;
             $b = $rgb & 0xff;
             $gs = $r * 0.299 + $g * 0.587 + $b * 0.114;
             imagesetpixel($dst_im, $x, $y, $palette[$gs]);
         }
     }
     $this->media->setImage($dst_im);
 }
 private function cropBilde($sti, $filnavn, $nyttFilnavn, $cropBredde, $cropHoyde)
 {
     $gammeltBilde = $sti . $filnavn;
     $bi = @ImageCreateFromJPEG($gammeltBilde) or $bi = @ImageCreateFromPNG($gammeltBilde) or $bi = @ImageCreateFromGIF($gammeltBilde) or $bi = false;
     if ($bi) {
         $naStorrelse = @getimagesize($gammeltBilde);
         $bredde = $naStorrelse[0];
         $hoyde = $naStorrelse[1];
         $nyBreddeNy = $bredde / $cropBredde;
         $nyHoydeNy = $hoyde / $cropHoyde;
         $halvertHoyde = $cropHoyde / 2;
         $halvertBredde = $cropBredde / 2;
         $thumb = @ImageCreateTrueColor($cropBredde, $cropHoyde);
         if ($bredde > $hoyde) {
             $tilpassetBredde = $bredde / $nyHoydeNy;
             $halvBredde = $tilpassetBredde / 2;
             $intBredde = $halvBredde - $halvertBredde;
             @ImageCopyResampled($thumb, $bi, -$intBredde, 0, 0, 0, $tilpassetBredde, $cropHoyde, $bredde, $hoyde);
         } elseif ($bredde < $hoyde || $bredde == $hoyde) {
             $tilPassetHoyde = $hoyde / $nyBreddeNy;
             $halvHoyde = $tilPassetHoyde / 2;
             $intHoyde = $halvHoyde - $halvertHoyde;
             @ImageCopyResampled($thumb, $bi, 0, -$intHoyde, 0, 0, $cropBredde, $tilPassetHoyde, $bredde, $hoyde);
         } else {
             @ImageCopyResampled($thumb, $bi, 0, 0, 0, 0, $cropBredde, $cropHoyde, $bredde, $hoyde);
         }
         @imagejpeg($thumb, $sti . $nyttFilnavn, 50);
         return $nyttFilnavn;
     } else {
         return -1;
     }
 }
Example #15
0
 public function resize_image($data, $imgX, $sizedef, $lid, $imgid)
 {
     $file = $data["raw_name"];
     $type = $data["file_ext"];
     $outfile = $imgX[$sizedef]['dir'] . "/" . $lid . "/" . $file . '.jpg';
     $path = $this->config->item("upload_dir");
     $image = $this->create_image_container($file, $type);
     if ($image) {
         $size = GetImageSize($path . $file . $type);
         $old = $image;
         // сей форк - не просто так. непонятно, правда, почему...
         if ($size['1'] < $size['0']) {
             $h_new = round($imgX[$sizedef]['max_dim'] * ($size['1'] / $size['0']));
             $measures = array($imgX[$sizedef]['max_dim'], $h_new);
         }
         if ($size['1'] >= $size['0']) {
             $h_new = round($imgX[$sizedef]['max_dim'] * ($size['0'] / $size['1']));
             $measures = array($h_new, $imgX[$sizedef]['max_dim']);
         }
         $new = ImageCreateTrueColor($measures[0], $measures[1]);
         ImageCopyResampled($new, $image, 0, 0, 0, 0, $measures[0], $measures[1], $size['0'], $size['1']);
         imageJpeg($new, $outfile, $imgX[$sizedef]['quality']);
         $this->db->query("UPDATE `images` SET `images`.`" . $sizedef . "` = ? WHERE `images`.`id` = ?", array(implode($measures, ","), $imgid));
         imageDestroy($new);
     }
 }
Example #16
0
/**
 *
 * long description
 * @global object
 * @param object $dst_img
 * @param object $src_img
 * @param int $dst_x 
 * @param int $dst_y 
 * @param int $src_x 
 * @param int $src_y 
 * @param int $dst_w 
 * @param int $dst_h 
 * @param int $src_w 
 * @param int $src_h 
 * @return bool
 * @todo Finish documenting this function
 */
function ImageCopyBicubic($dst_img, $src_img, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h)
{
    global $CFG;
    if (function_exists('ImageCopyResampled') and $CFG->gdversion >= 2) {
        return ImageCopyResampled($dst_img, $src_img, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
    }
    $totalcolors = imagecolorstotal($src_img);
    for ($i = 0; $i < $totalcolors; $i++) {
        if ($colors = ImageColorsForIndex($src_img, $i)) {
            ImageColorAllocate($dst_img, $colors['red'], $colors['green'], $colors['blue']);
        }
    }
    $scaleX = ($src_w - 1) / $dst_w;
    $scaleY = ($src_h - 1) / $dst_h;
    $scaleX2 = $scaleX / 2.0;
    $scaleY2 = $scaleY / 2.0;
    for ($j = 0; $j < $dst_h; $j++) {
        $sY = $j * $scaleY;
        for ($i = 0; $i < $dst_w; $i++) {
            $sX = $i * $scaleX;
            $c1 = ImageColorsForIndex($src_img, ImageColorAt($src_img, (int) $sX, (int) $sY + $scaleY2));
            $c2 = ImageColorsForIndex($src_img, ImageColorAt($src_img, (int) $sX, (int) $sY));
            $c3 = ImageColorsForIndex($src_img, ImageColorAt($src_img, (int) $sX + $scaleX2, (int) $sY + $scaleY2));
            $c4 = ImageColorsForIndex($src_img, ImageColorAt($src_img, (int) $sX + $scaleX2, (int) $sY));
            $red = (int) (($c1['red'] + $c2['red'] + $c3['red'] + $c4['red']) / 4);
            $green = (int) (($c1['green'] + $c2['green'] + $c3['green'] + $c4['green']) / 4);
            $blue = (int) (($c1['blue'] + $c2['blue'] + $c3['blue'] + $c4['blue']) / 4);
            $color = ImageColorClosest($dst_img, $red, $green, $blue);
            ImageSetPixel($dst_img, $i + $dst_x, $j + $dst_y, $color);
        }
    }
}
Example #17
0
function ImageResize($srcFile, $toW, $toH, $toFile = "")
{
    if ($toFile == "") {
        $toFile = $srcFile;
    }
    $info = "";
    $data = GetImageSize($srcFile, $info);
    switch ($data[2]) {
        case 1:
            if (!function_exists("imagecreatefromgif")) {
                echo "你的GD库不能使用GIF格式的图片,请使用Jpeg或PNG格式!<a href='javascript:go(-1);'>返回</a>";
                exit;
            }
            $im = ImageCreateFromGIF($srcFile);
            break;
        case 2:
            if (!function_exists("imagecreatefromjpeg")) {
                echo "你的GD库不能使用jpeg格式的图片,请使用其它格式的图片!<a href='javascript:go(-1);'>返回</a>";
                exit;
            }
            $im = ImageCreateFromJpeg($srcFile);
            break;
        case 3:
            $im = ImageCreateFromPNG($srcFile);
            break;
    }
    $srcW = ImageSX($im);
    $srcH = ImageSY($im);
    $toWH = $toW / $toH;
    $srcWH = $srcW / $srcH;
    if ($toWH <= $srcWH) {
        $ftoW = $toW;
        $ftoH = $ftoW * ($srcH / $srcW);
    } else {
        $ftoH = $toH;
        $ftoW = $ftoH * ($srcW / $srcH);
    }
    if ($srcW > $toW || $srcH > $toH) {
        if (function_exists("imagecreatetruecolor")) {
            @($ni = ImageCreateTrueColor($ftoW, $ftoH));
            if ($ni) {
                ImageCopyResampled($ni, $im, 0, 0, 0, 0, $ftoW, $ftoH, $srcW, $srcH);
            } else {
                $ni = ImageCreate($ftoW, $ftoH);
                ImageCopyResized($ni, $im, 0, 0, 0, 0, $ftoW, $ftoH, $srcW, $srcH);
            }
        } else {
            $ni = ImageCreate($ftoW, $ftoH);
            ImageCopyResized($ni, $im, 0, 0, 0, 0, $ftoW, $ftoH, $srcW, $srcH);
        }
        if (function_exists('imagejpeg')) {
            ImageJpeg($ni, $toFile);
        } else {
            ImagePNG($ni, $toFile);
        }
        ImageDestroy($ni);
    }
    ImageDestroy($im);
}
 function pcs_href_image($src_path)
 {
     $strRet = DIR_WS_IMAGES . 'pcs_images/' . basename($src_path) . '_' . MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_HEIGHT . '_' . MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_WIDTH . '_' . MODULE_ADDONS_PCSLIDESHOW_IMAGE_QUALITY . '.jpg';
     #This will be the filename of the resized image.
     if (!file_exists($strRet)) {
         #Create the file if it does not exist
         #check to see if source file exists
         if (!file_exists($src_path)) {
             return 'error1';
             #check to see if source file is readable
         } elseif (!is_readable($src_path)) {
             return 'error2';
         }
         #check if gif
         if (stristr(strtolower($src_path), '.gif')) {
             $oldImage = ImageCreateFromGif($src_path);
         } elseif (stristr(strtolower($src_path), '.jpg') || stristr(strtolower($src_path), '.jpeg')) {
             $oldImage = ImageCreateFromJpeg($src_path);
         } elseif (stristr(strtolower($src_path), '.png')) {
             $oldImage = ImageCreateFromPng($src_path);
         } else {
             return 'error3';
         }
         #Create the new image
         if (function_exists("ImageCreateTrueColor")) {
             $newImage = ImageCreateTrueColor(MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_WIDTH, MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_HEIGHT);
         } else {
             $newImage = ImageCreate(MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_WIDTH, MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_HEIGHT);
         }
         $backgroundColor = imagecolorallocate($newImage, 255, 255, 255);
         imagefill($newImage, 0, 0, $backgroundColor);
         #calculate the rezised image's dimmensions
         if (imagesx($oldImage) > MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_WIDTH || imagesy($oldImage) > MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_HEIGHT) {
             #Resize image
             if (imagesx($oldImage) / MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_WIDTH > imagesy($oldImage) / MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_HEIGHT) {
                 #Width is leading in beeing to large
                 $newWidth = (int) MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_WIDTH;
                 $newHeight = (int) MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_WIDTH / imagesx($oldImage) * imagesy($oldImage);
             } else {
                 #Height is leading in beeing to large
                 $newHeight = (int) MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_HEIGHT;
                 $newWidth = (int) MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_HEIGHT / imagesy($oldImage) * imagesx($oldImage);
             }
         } else {
             #Don't rezise image
             $newWidth = imagesx($oldImage);
             $newHeight = imagesy($oldImage);
         }
         #Copy the old image onto the new image
         ImageCopyResampled($newImage, $oldImage, MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_WIDTH / 2 - $newWidth / 2, MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_HEIGHT / 2 - $newHeight / 2, 0, 0, $newWidth, $newHeight, imagesx($oldImage), imagesy($oldImage));
         imagejpeg($newImage, $strRet, MODULE_ADDONS_PCSLIDESHOW_IMAGE_QUALITY);
         #save the image
         imagedestroy($oldImage);
         #Free Memory
         imagedestroy($newImage);
         #Free memory
     }
     return $strRet;
 }
function makeThumb($path, $size, $mime = FALSE)
{
    // Verifica se é uma imagem
    // @since rev 1
    if ($mime === FALSE) {
        $mime = mime_content_type($path);
    }
    if (strpos($mime, "jpeg") !== FALSE) {
        $buffer = imagecreatefromjpeg($path);
    } elseif (strpos($mime, "bmp") !== FALSE) {
        $buffer = imagecreatefrombmp($path);
    } elseif (strpos($mime, "gif") !== FALSE) {
        $buffer = imagecreatefromgif($path);
    } elseif (strpos($mime, "png") !== FALSE) {
        $buffer = imagecreatefrompng($path);
    } else {
        return FALSE;
    }
    if ($buffer === FALSE) {
        return FALSE;
    }
    // Busca o tamanho da imagem
    // @since rev 1
    $x = $origem_x = ImagesX($buffer);
    $y = $origem_y = ImagesY($buffer);
    // Verifica qual deve ser a proporção
    // @since rev 1
    if ($x >= $y) {
        if ($x > $size) {
            $x1 = (int) ($x * ($size / $x));
            $y1 = (int) ($y * ($size / $x));
        } else {
            $x1 = $x;
            $y1 = $y;
        }
    } else {
        if ($y > $size) {
            $x1 = (int) ($x * ($size / $y));
            $y1 = (int) ($y * ($size / $y));
        } else {
            $x1 = $x;
            $y1 = $y;
        }
    }
    // Muda o tamanho da imagem
    // @since rev 1
    $image = ImageCreateTrueColor($x1, $y1);
    if ($image === FALSE) {
        return FALSE;
    }
    ImageCopyResampled($image, $buffer, 0, 0, 0, 0, $x1 + 1, $y1 + 1, $origem_x, $origem_y);
    // Libera recursos
    // @since rev 1
    ImageDestroy($buffer);
    // Retorna o resource
    // @since rev 1
    return $image;
}
Example #20
0
function ResizeImage($Filename, $Thumbnail, $Size)
{
    $Path = pathinfo($Filename);
    $Extension = $Path['extension'];
    $ImageData = @GetImageSize($Filename);
    $Width = $ImageData[0];
    $Height = $ImageData[1];
    if ($Width >= $Height and $Width > $Size) {
        $NewWidth = $Size;
        $NewHeight = $Size / $Width * $Height;
    } elseif ($Height >= $Width and $Height > $Size) {
        $NewWidth = $Size / $Height * $Width;
        $NewHeight = $Size;
    } else {
        $NewWidth = $Width;
        $NewHeight = $Height;
    }
    $NewImage = @ImageCreateTrueColor($NewWidth, $NewHeight);
    if (preg_match('/^gif$/i', $Extension)) {
        $Image = @ImageCreateFromGif($Filename);
    } elseif (preg_match('/^png$/i', $Extension)) {
        $Image = @ImageCreateFromPng($Filename);
    } else {
        $Image = @ImageCreateFromJpeg($Filename);
    }
    if ($ImageData[2] == IMAGETYPE_GIF or $ImageData[2] == IMAGETYPE_PNG) {
        $TransIndex = imagecolortransparent($Image);
        // If we have a specific transparent color
        if ($TransIndex >= 0) {
            // Get the original image's transparent color's RGB values
            $TransColor = imagecolorsforindex($Image, $TransIndex);
            // Allocate the same color in the new image resource
            $TransIndex = imagecolorallocate($NewImage, $TransColor['red'], $TransColor['green'], $TransColor['blue']);
            // Completely fill the background of the new image with allocated color.
            imagefill($NewImage, 0, 0, $TransIndex);
            // Set the background color for new image to transparent
            imagecolortransparent($NewImage, $TransIndex);
        } elseif ($ImageData[2] == IMAGETYPE_PNG) {
            // Turn off transparency blending (temporarily)
            imagealphablending($NewImage, false);
            // Create a new transparent color for image
            $color = imagecolorallocatealpha($NewImage, 0, 0, 0, 127);
            // Completely fill the background of the new image with allocated color.
            imagefill($NewImage, 0, 0, $color);
            // Restore transparency blending
            imagesavealpha($NewImage, true);
        }
    }
    @ImageCopyResampled($NewImage, $Image, 0, 0, 0, 0, $NewWidth, $NewHeight, $Width, $Height);
    if (preg_match('/^gif$/i', $Extension)) {
        @ImageGif($NewImage, $Thumbnail);
    } elseif (preg_match('/^png$/i', $Extension)) {
        @ImagePng($NewImage, $Thumbnail);
    } else {
        @ImageJpeg($NewImage, $Thumbnail);
    }
    @chmod($Thumbnail, 0644);
}
 public function scaleToWidthRatio($targetWidth)
 {
     if ($this->originalWidth > $targetWidth) {
         $targetHeight = (int) ($targetWidth / $this->originalRatio);
         $this->targetImage = ImageCreateTrueColor($targetWidth, $targetHeight);
         ImageCopyResampled($this->targetImage, $this->originalImage, 0, 0, 0, 0, $targetWidth, $targetHeight, $this->originalWidth, $this->originalHeight);
     } else {
         $this->targetImage = $this->originalImage;
     }
 }
Example #22
0
 function makeThumb($sourFile, $width = 128, $height = 128)
 {
     $imageInfo = $this->getInfo($sourFile);
     $sourFile = $this->sourcePath . $sourFile;
     $newName = substr($imageInfo["name"], 0, strrpos($imageInfo["name"], ".")) . "_thumb.jpg";
     switch ($imageInfo["type"]) {
         case 1:
             //gif
             $img = imagecreatefromgif($sourFile);
             break;
         case 2:
             //jpg
             $img = imagecreatefromjpeg($sourFile);
             break;
         case 3:
             //png
             $img = imagecreatefrompng($sourFile);
             break;
         default:
             return 0;
             break;
     }
     if (!$img) {
         return 0;
     }
     $width = $width > $imageInfo["width"] ? $imageInfo["width"] : $width;
     $height = $height > $imageInfo["height"] ? $imageInfo["height"] : $height;
     $srcW = $imageInfo["width"];
     $srcH = $imageInfo["height"];
     if ($srcW * $width > $srcH * $height) {
         $height = round($srcH * $width / $srcW);
     } else {
         $width = round($srcW * $height / $srcH);
     }
     //*
     if (function_exists("imagecreatetruecolor")) {
         $new = imagecreatetruecolor($width, $height);
         ImageCopyResampled($new, $img, 0, 0, 0, 0, $width, $height, $imageInfo["width"], $imageInfo["height"]);
     } else {
         $new = imagecreate($width, $height);
         ImageCopyResized($new, $img, 0, 0, 0, 0, $width, $height, $imageInfo["width"], $imageInfo["height"]);
     }
     //*/
     if ($this->toFile) {
         if (file_exists($this->thumbPath . $newName)) {
             unlink($this->thumbPath . $newName);
         }
         imagejpeg($new, $this->thumbPath . $newName, 100);
         return $this->thumbPath . $newName;
     } else {
         imagejpeg($new);
     }
     imagedestroy($new);
     imagedestroy($img);
 }
Example #23
0
function scale($img, $maxwidth, $maxheight)
{
    $imginfo = getimagesize($img);
    $imgwidth = $imginfo[0];
    $imgheight = $imginfo[1];
    if ($imgwidth > $maxwidth) {
        $ration = $maxwidth / $imgwidth;
        $newwidth = round($imgwidth * $ration);
        $newheight = round($imgheight * $ration);
        if ($newheight > $maxheight) {
            $ration = $maxheight / $newheight;
            $newwidth = round($newwidth * $ration);
            $newheight = round($newheight * $ration);
            $dst_img = ImageCreateTrueColor($newwidth, $newheight);
            $image = imagecreatefromjpeg($img);
            ImageCopyResampled($dst_img, $image, 0, 0, 0, 0, $newwidth, $newheight, $imgwidth, $imgheight);
            ImageJpeg($dst_img, $img, 90);
            ImageDestroy($dst_img);
        } else {
            $dst_img = ImageCreateTrueColor($newwidth, $newheight);
            $image = imagecreatefromjpeg($img);
            ImageCopyResampled($dst_img, $image, 0, 0, 0, 0, $newwidth, $newheight, $imgwidth, $imgheight);
            ImageJpeg($dst_img, $img, 90);
            ImageDestroy($dst_img);
        }
    } else {
        if ($imgheight > $maxheight) {
            $ration = $maxheight / $imgheight;
            $newwidth = round($imgwidth * $ration);
            $newheight = round($imgheight * $ration);
            if ($newwidth > $maxwidth) {
                $ration = $maxwidth / $newwidth;
                $newwidth = round($newwidth * $ration);
                $newheight = round($newheight * $ration);
                $dst_img = ImageCreateTrueColor($newwidth, $newheight);
                $image = imagecreatefromjpeg($img);
                ImageCopyResampled($dst_img, $image, 0, 0, 0, 0, $newwidth, $newheight, $imgwidth, $imgheight);
                ImageJpeg($dst_img, $img, 90);
                ImageDestroy($dst_img);
            } else {
                $dst_img = ImageCreateTrueColor($newwidth, $newheight);
                $image = imagecreatefromjpeg($img);
                ImageCopyResampled($dst_img, $image, 0, 0, 0, 0, $newwidth, $newheight, $imgwidth, $imgheight);
                ImageJpeg($dst_img, $img, 90);
                ImageDestroy($dst_img);
            }
        } else {
            $dst_img = ImageCreateTrueColor($newwidth, $newheight);
            $image = imagecreatefromjpeg($img);
            ImageCopyResampled($dst_img, $image, 0, 0, 0, 0, $newwidth, $newheight, $imgwidth, $imgheight);
            ImageJpeg($dst_img, $img, 90);
            ImageDestroy($dst_img);
        }
    }
}
Example #24
0
 function main($inFile)
 {
     $img = ImageCreateFromPNG($inFile);
     $width = ImageSX($img);
     $height = ImageSY($img);
     if ($width != 640 || $height != 960) {
         $resizedImg = ImageCreateTrueColor(640, 960);
         ImageCopyResampled($resizedImg, $img, 0, 0, 0, 0, 640, 960, $width, $height);
         $img = $resizedImg;
     }
     $this->extractAppInfo($img);
 }
Example #25
0
function makeThumb($_fileId, $_fileName, $_sizeSens, $_maxSize, $rep)
{
    $type_aut = array('.jpg', '.jpeg', '.jpe');
    $thumbName = 'thumb_' . $_fileId . '_' . $_maxSize;
    if (!in_array(strtolower(strrchr($_fileName, '.')), $type_aut)) {
        echo 'ERR format<br>';
        return false;
    }
    $img_infos = getimagesize($_fileName);
    $img_width = $img_infos[0];
    $img_height = $img_infos[1];
    switch ($img_infos[2]) {
        case 2:
            $img_type = 'jpg';
            $src_img = imagecreatefromjpeg($_fileName);
            break;
        default:
            echo 'ERR format 2<br>';
            return false;
            break;
    }
    $rapport = $img_width / $img_height;
    $new_width = $img_width;
    $new_height = $img_height;
    //	Redimensionnement sur la hauteur si image en mode portrait
    // if( $img_height > $img_width  ){
    if ($_sizeSens == 'h') {
        if ($img_height > $_maxSize) {
            $new_height = $_maxSize;
            $new_width = $new_height * $rapport;
        }
        //	Mode paysage
        // }elseif( $img_width > $_maxSize ){
    } elseif ($_sizeSens == 'w') {
        $new_width = $_maxSize;
        $new_height = $_maxSize / $rapport;
    }
    $new_img = ImageCreateTrueColor($new_width, $new_height);
    ImageCopyResampled($new_img, $src_img, 0, 0, 0, 0, $new_width, $new_height, $img_width, $img_height);
    /*
    if( !is_dir( $rep ) ){
    	echo 'ERR rep '.$rep.'<br>';
    	return false;
    }
    */
    // if( @!imagejpeg( $new_img, $rep.'/'.$thumbName.'.jpg', 100 ) ){
    if (!imagejpeg($new_img, $rep . '/' . $thumbName . '.jpg', 100)) {
        echo 'ERR ecriture img ' . $_fileName . '<br>';
        return false;
    }
    return true;
}
Example #26
0
 private static function img_resizer($src, $quality, $w, $h, $saveas)
 {
     /* v2.5 with auto crop */
     $r = 1;
     $e = strtolower(substr($src, strrpos($src, ".") + 1, 3));
     if ($e == "jpg" || $e == "jpeg") {
         $OldImage = imagecreatefromjpeg($src) or $r = 0;
     } elseif ($e == "gif") {
         $OldImage = ImageCreateFromGif($src) or $r = 0;
     } elseif ($e == "bmp") {
         $OldImage = ImageCreateFromwbmp($src) or $r = 0;
     } elseif ($e == "png") {
         $OldImage = ImageCreateFromPng($src) or $r = 0;
     } else {
         _o("No es una imagen v&aacute;lida! (" . $e . ") -- " . $src);
         $r = 0;
     }
     if ($r) {
         list($width, $height) = getimagesize($src);
         // check if ratios match
         $_ratio = array($width / $height, $w / $h);
         if ($_ratio[0] != $_ratio[1]) {
             // crop image
             // find the right scale to use
             $_scale = min((double) ($width / $w), (double) ($height / $h));
             // coords to crop
             $cropX = (double) ($width - $_scale * $w);
             $cropY = (double) ($height - $_scale * $h);
             // cropped image size
             $cropW = (double) ($width - $cropX);
             $cropH = (double) ($height - $cropY);
             $crop = ImageCreateTrueColor($cropW, $cropH);
             // crop the middle part of the image to fit proportions
             ImageCopy($crop, $OldImage, 0, 0, (int) ($cropX / 2), (int) ($cropY / 2), $cropW, $cropH);
         }
         // do the thumbnail
         $NewThumb = ImageCreateTrueColor($w, $h);
         if (isset($crop)) {
             // been cropped
             ImageCopyResampled($NewThumb, $crop, 0, 0, 0, 0, $w, $h, $cropW, $cropH);
             ImageDestroy($crop);
         } else {
             // ratio match, regular resize
             ImageCopyResampled($NewThumb, $OldImage, 0, 0, 0, 0, $w, $h, $width, $height);
         }
         _ckdir($saveas);
         ImageJpeg($NewThumb, $saveas, $quality);
         ImageDestroy($NewThumb);
         ImageDestroy($OldImage);
     }
     return $r;
 }
Example #27
0
function SetImgSize($img, $W = 0, $H = 0, $Key = 1)
{
    //echo("$img , $W ,$H , $Key");
    $rasshr = substr(strrchr($img, '.'), 1);
    //организация работы с форматами GIF JPEG PNG
    switch ($rasshr) {
        default:
        case "gif":
            $srcImage = @ImageCreateFromGIF($img);
            break;
        case "jpg":
            $srcImage = @ImageCreateFromJPEG($img);
            break;
        case "png":
            $srcImage = @ImageCreateFromPNG($img);
            break;
    }
    //определяем изначальную длинну и высоту
    $srcWidth = @ImageSX($srcImage);
    $srcHeight = @ImageSY($srcImage);
    //ресайз по заданной ширине
    if ($W != 0 && $H == 0 && $W < $srcWidth) {
        $res = ResNoDel($srcWidth, $srcHeight, $W, 0);
    }
    //ресайз по заданной высоте
    if ($W == 0 && $H != 0 && $H < $srcHeight) {
        $res = ResNoDel($srcWidth, $srcHeight, 0, $H);
    }
    //ресайз с обрезкой
    if ($W != 0 && $H != 0 && ($H < $srcHeight || $W < $srcWidth)) {
        $res = ResDel($srcWidth, $srcHeight, min($W, $srcWidth), min($H, $srcHeight), $Key);
    }
    //создаем картинку
    if ($res) {
        $endImage = @ImageCreateTrueColor($res[2], $res[3]);
        ImageCopyResampled($endImage, $srcImage, 0, 0, $res[0], $res[1], $res[2], $res[3], $res[4], $res[5]);
        unlink($img);
        switch ($rasshr) {
            case "gif":
                ImageGif($endImage, $img);
                break;
            default:
            case "jpg":
                imagejpeg($endImage, $img);
                break;
            case "png":
                imagepng($endImage, $img);
                break;
        }
        ImageDestroy($endImage);
    }
}
Example #28
0
function resize($images, $filename)
{
    $width = 500;
    $size = getimagesize($images);
    $height = round($width * $size[1] / $size[0]);
    $images_orig = ImageCreateFromJPEG($images);
    $photoX = imagesx($images_orig);
    $photoY = imagesy($images_orig);
    $images_fin = imagecreatetruecolor($width, $height);
    ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width + 1, $height + 1, $photoX, $photoY);
    ImageJPEG($images_fin, $GLOBALS['root'] . '/images/' . $filename);
    ImageDestroy($images_orig);
    ImageDestroy($images_fin);
}
Example #29
0
function process_img(&$img)
{
    $width = imagesx($img);
    $height = imagesy($img);
    $w = array(0, $width / 2);
    $h = array(0, $height / 2);
    $left = ImageCreateTrueColor($w[1], $h[1]);
    ImageCopyResampled($left, $img, 0, 0, $w[0], $h[0], $w[1], $h[1], $w[1], $h[1]);
    $w = array($w[1], $w[1]);
    $h = array($h[1], $h[1]);
    $left = ImageCreateTrueColor($w[1], $h[1]);
    ImageCopyResampled($left, $img, 0, 0, $w[0], $h[0], $w[1], $h[1], $w[1], $h[1]);
    $img = $left;
}
Example #30
-1
 public static function ResizeImage($Img, $w)
 {
     $filename = $_SERVER["DOCUMENT_ROOT"] . JURI::root(true) . "/" . $Img;
     $images = $filename;
     $new_images = $_SERVER["DOCUMENT_ROOT"] . JURI::root(true) . "/thumb/" . $Img;
     //copy("/images/thumb/"$_FILES,"Photos/".$_FILES["userfile"]["name"]);
     $width = $w;
     //*** Fix Width & Heigh (Autu caculate) ***//
     $size = GetimageSize($images);
     $height = round($width * $size[1] / $size[0]);
     if ($size[0] == "250") {
         return "The logo has the right width. Doesn't make sense resize it! Good job!";
     }
     $images_orig = ImageCreateFromJPEG($images);
     $photoX = ImagesX($images_orig);
     $photoY = ImagesY($images_orig);
     $images_fin = ImageCreateTrueColor($width, $height);
     $result = ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width + 1, $height + 1, $photoX, $photoY);
     ImageJPEG($images_fin, $filename);
     ImageDestroy($images_orig);
     ImageDestroy($images_fin);
     if ($result) {
         return "Logo resized to " . $width . "px by " . $height . "px";
     } else {
         return "mmm It looks like something unexpected just happened, ask Jose!";
     }
 }