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);
 }
Example #2
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}");
}
function recorta_imagem_perfil_usuario()
{
    // imagem normal
    $targ_w[0] = TAMANHO_IMG_PERFIL_RECORTAR_LARGURA;
    $targ_h[0] = TAMANHO_IMG_PERFIL_RECORTAR_ALTURA;
    // imagem miniatura
    $targ_w[1] = TAMANHO_IMG_PERFIL_RECORTAR_LARGURA_MIN;
    $targ_h[1] = TAMANHO_IMG_PERFIL_RECORTAR_ALTURA_MIN;
    // qualidade
    $jpeg_quality = 100;
    // criando nova imagem
    $src[0] = remove_html($_REQUEST['imagem_perfil']);
    $img_r[0] = imagecreatefromjpeg($src[0]);
    $dst_r[0] = ImageCreateTrueColor($targ_w[0], $targ_h[0]);
    imagecopyresampled($dst_r[0], $img_r[0], 0, 0, $_POST['x'], $_POST['y'], $targ_w[0], $targ_h[0], $_POST['w'], $_POST['h']);
    // criando nova imagem
    $src[1] = remove_html($_REQUEST['imagem_perfil']);
    $img_r[1] = imagecreatefromjpeg($src[1]);
    $dst_r[1] = ImageCreateTrueColor($targ_w[1], $targ_h[1]);
    imagecopyresampled($dst_r[1], $img_r[1], 0, 0, $_POST['x'], $_POST['y'], $targ_w[1], $targ_h[1], $_POST['w'], $_POST['h']);
    // dados da imagem
    $dados_imagem = retorne_imagem_perfil_usuario_root();
    // dados de retorno
    $imagem_perfil = $dados_imagem['imagem_perfil'];
    $imagem_perfil_miniatura = $dados_imagem['imagem_perfil_miniatura'];
    // grava a nova imagem
    imagejpeg($dst_r[0], $imagem_perfil);
    imagejpeg($dst_r[1], $imagem_perfil_miniatura);
    // chama a pagina inicial
    chama_pagina_inicial();
}
Example #4
0
 /**
  * crop image
  */
 public static function crop($filename, $x, $y, $w, $h, $targ_w, $targ_h)
 {
     $extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
     switch ($extension) {
         case 'gif':
             $img_r = imagecreatefromgif($filename);
             $dst_r = ImageCreateTrueColor($targ_w, $targ_h);
             imagecopyresampled($dst_r, $img_r, 0, 0, $x, $y, $targ_w, $targ_h, $w, $h);
             imagegif($dst_r, $filename);
             break;
         case 'jpg':
         case 'jpeg':
             $img_r = imagecreatefromjpeg($filename);
             $dst_r = ImageCreateTrueColor($targ_w, $targ_h);
             imagecopyresampled($dst_r, $img_r, 0, 0, $x, $y, $targ_w, $targ_h, $w, $h);
             imagejpeg($dst_r, $filename, 75);
             break;
         case 'png':
             $img_r = imagecreatefrompng($filename);
             $dst_r = ImageCreateTrueColor($targ_w, $targ_h);
             imagealphablending($dst_r, false);
             imagesavealpha($dst_r, true);
             imagecopyresampled($dst_r, $img_r, 0, 0, $x, $y, $targ_w, $targ_h, $w, $h);
             imagepng($dst_r, $filename, 9);
             break;
         default:
             return false;
     }
     return true;
 }
function TransFormPicture($inputfname, $outputfname, $transform, $backgroundcolor)
{
    $img_in = ImageCreateFromPNG($inputfname);
    $sizex = imagesx($img_in);
    $sizey = imagesy($img_in);
    $img_out = @ImageCreateTrueColor($sizex, $sizey) or die("Cannot create image handle.");
    imagefill($img_out, 0, 0, hexdec($backgroundcolor));
    ImageCopy($img_out, $img_in, 0, 0, 0, 0, $sizex, $sizey);
    for ($x = 0; $x < $sizex; $x++) {
        for ($y = 0; $y < $sizey; $y++) {
            $color = imagecolorat($img_in, $x, $y);
            $allcolors[dechex($color)]++;
            $blue = 0xff & $color;
            $green = (0xff00 & $color) >> 8;
            $red = (0xff0000 & $color) >> 16;
            foreach ($transform as $line) {
                list($from, $to) = split("\t", $line);
                list($fr, $fg, $fb) = sscanf($from, '%2x%2x%2x');
                if ($blue == $fb and $red == $fr and $green == $fg) {
                    imagesetpixel($img_out, $x, $y, hexdec($to));
                }
            }
        }
    }
    ImagePNG($img_out, "out/{$outputfname}");
    imagedestroy($img_in);
    imagedestroy($img_out);
    print_r($allcolors);
}
 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 #7
0
function Resampling($tmp_name, $directorio, $name)
{
    // Indico el destino del directorio de la imagen
    $imagen_origen = ImageCreateFromJPEG($tmp_name);
    // Calculo el tamaño de la imagen original
    $tam_ancho = imagesx($imagen_origen);
    $tam_alto = imagesy($imagen_origen);
    //Calculo la medida que va a tener
    if ($tam_ancho >= $tam_alto) {
        $ancho = 38;
        $alto = 38 * $tam_alto / $tam_ancho;
    } else {
        $ancho = 38 * $tam_ancho / $tam_alto;
        $alto = 38;
    }
    //Creo una imagen
    $imagen_destino = ImageCreateTrueColor($ancho, $alto);
    //Resize
    imagecopyresized($imagen_destino, $imagen_origen, 0, 0, 0, 0, $ancho, $alto, $tam_ancho, $tam_alto);
    $nombre_destino = $directorio . $name;
    //Genero Copia Destino
    ImageJPEG($imagen_destino, $nombre_destino, 100);
    //Borro imagen virtual
    ImageDestroy($imagen_destino);
}
 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);
 }
Example #9
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;
 }
 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 #11
0
function createthumb($name, $filename, $new_w, $new_h)
{
    $system = explode(".", $name);
    if (preg_match("/jpg|jpeg/", $system[1])) {
        $src_img = imagecreatefromjpeg($name);
    }
    if (preg_match("/png/", $system[1])) {
        $src_img = imagecreatefrompng($name);
    }
    $old_x = imageSX($src_img);
    $old_y = imageSY($src_img);
    if ($old_x > $old_y) {
        $thumb_w = $new_w;
        $thumb_h = $old_y * ($new_h / $old_x);
    }
    if ($old_x < $old_y) {
        $thumb_w = $old_x * ($new_w / $old_y);
        $thumb_h = $new_h;
    }
    if ($old_x == $old_y) {
        $thumb_w = $new_w;
        $thumb_h = $new_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);
    if (preg_match("/png/", $system[1])) {
        imagepng($dst_img, $filename);
    } else {
        imagejpeg($dst_img, $filename);
    }
    imagedestroy($dst_img);
    imagedestroy($src_img);
}
Example #12
0
/**
 *	Generate a thumbnail from an image
 *
 */
function make_thumb($source, $destination, $size)
{
    // Check if GD is installed
    if (extension_loaded('gd') && function_exists('imageCreateFromJpeg')) {
        // First figure out the size of the thumbnail
        list($original_x, $original_y) = getimagesize($source);
        if ($original_x > $original_y) {
            $thumb_w = $size;
            $thumb_h = $original_y * ($size / $original_x);
        }
        if ($original_x < $original_y) {
            $thumb_w = $original_x * ($size / $original_y);
            $thumb_h = $size;
        }
        if ($original_x == $original_y) {
            $thumb_w = $size;
            $thumb_h = $size;
        }
        // Now make the thumbnail
        $source = imageCreateFromJpeg($source);
        $dst_img = ImageCreateTrueColor($thumb_w, $thumb_h);
        imagecopyresampled($dst_img, $source, 0, 0, 0, 0, $thumb_w, $thumb_h, $original_x, $original_y);
        imagejpeg($dst_img, $destination);
        // Clear memory
        imagedestroy($dst_img);
        imagedestroy($source);
        // Return true
        return true;
    } else {
        return false;
    }
}
Example #13
0
function ResizeImage($image_from, $image_to, $fitwidth = 200, $fitheight = 270, $quality = 75)
{
    $os = $originalsize = getimagesize($image_from);
    if ($originalsize[2] != 2 && $originalsize[2] != 3 && $originalsize[2] != 6 && ($originalsize[2] < 9 or $originalsize[2] > 12)) {
        return false;
    }
    if ($originalsize[0] > $fitwidth or $originalsize[1] > $fitheight) {
        $h = getimagesize($image_from);
        if ($h[0] / $fitwidth > $h[1] / $fitheight) {
            $fitheight = $h[1] * $fitwidth / $h[0];
        } else {
            $fitwidth = $h[0] * $fitheight / $h[1];
        }
        if ($os[2] == 2 or $os[2] >= 9 && $os[2] <= 12) {
            $i = ImageCreateFromJPEG($image_from);
        }
        $o = ImageCreateTrueColor($fitwidth, $fitheight);
        imagecopyresampled($o, $i, 0, 0, 0, 0, $fitwidth, $fitheight, $h[0], $h[1]);
        imagejpeg($o, $image_to, $quality);
        chmod($image_to, 0777);
        imagedestroy($o);
        imagedestroy($i);
        return 2;
    }
    if ($originalsize[0] <= $fitwidth && $originalsize[1] <= $fitheight) {
        $i = ImageCreateFromJPEG($image_from);
        imagejpeg($i, $image_to, $quality);
        chmod($image_to, 0777);
        return 1;
    }
}
function resizeImg($origPath, $mW, $mH)
{
    // Read the size
    $rst['size'] = GetImageSize($origPath);
    $w = $rst['size'][0];
    $h = $rst['size'][1];
    // Proportionally resize the image to the max sizes specified above
    $xRatio = $mW / $w;
    $yRatio = $mH / $h;
    if ($w <= $mW && $h <= $mH) {
        $tnW = $w;
        $tnH = $h;
    } elseif ($xRatio * $h < $mH) {
        $tnH = ceil($xRatio * $h);
        $tnW = $mW;
    } else {
        $tnW = ceil($yRatio * $w);
        $tnH = $mH;
    }
    // Create the new image!
    if ($rst['size']['mime'] == 'image/jpg' || $rst['size']['mime'] == 'image/jpeg') {
        $rst['src'] = imagecreatefromjpeg($origPath);
        $rst['dst'] = ImageCreateTrueColor($tnW, $tnH);
        $rst['resize'] = ImageCopyResized($rst['dst'], $rst['src'], 0, 0, 0, 0, $tnW, $tnH, $w, $h);
        $rst['imgMod'] = imagejpeg($rst['dst'], $origPath, 100);
    } else {
        $rst['note'] = 'Error with file type!';
        return false;
    }
    return $rst;
}
 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 #16
0
function createthumb($originalImage, $newName, $new_w, $new_h)
{
    $src_img = imagecreatefromjpeg($originalImage);
    $newName .= ".jpg";
    # Maintain proportions
    $old_x = imageSX($src_img);
    $old_y = imageSY($src_img);
    if ($old_x > $old_y) {
        $thumb_w = $new_w;
        $thumb_h = $old_y * ($new_h / $old_x);
    }
    if ($old_x < $old_y) {
        $thumb_w = $old_x * ($new_w / $old_y);
        $thumb_h = $new_h;
    }
    if ($old_x == $old_y) {
        $thumb_w = $new_w;
        $thumb_h = $new_h;
    }
    # Create destination-image-resource
    $dst_img = ImageCreateTrueColor($thumb_w, $thumb_h);
    # Copy source-image-resource to destination-image-resource
    imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y);
    # Create the final image from the destination-image-resource
    imagejpeg($dst_img, $newName);
    # Delete our image-resources
    imagedestroy($dst_img);
    imagedestroy($src_img);
    # Show results
    return $newName;
}
Example #17
0
 function scale($size = 100)
 {
     if (!$this->image && !$this->checked) {
         $this->get();
     }
     if (!$this->image) {
         return false;
     }
     if ($this->x > $this->y) {
         $percent = $size / $this->x;
     } else {
         $percent = $size / $this->y;
     }
     $min = min($this->x * $percent, $this->y * $percent);
     if ($min < $size / 2) {
         $percent = $percent * $size / 2 / $min;
     }
     // Ensure that minimum axis size is size/2
     $new_x = round($this->x * $percent);
     $new_y = round($this->y * $percent);
     $dst = ImageCreateTrueColor($new_x, $new_y);
     imagefill($dst, 0, 0, imagecolorallocate($dst, 255, 255, 255));
     if (imagecopyresampled($dst, $this->image, 0, 0, 0, 0, $new_x, $new_y, $this->x, $this->y)) {
         $this->image = $dst;
         $this->x = imagesx($this->image);
         $this->y = imagesy($this->image);
         return true;
     }
     return false;
 }
Example #18
0
 public function cropnsave($id)
 {
     $basepath = app_path() . '/storage/uploads/';
     $jpeg_quality = 90;
     $src = $basepath . 'resize_' . $id;
     if (ImageModel::getImgTypeByExtension($id) == ImageModel::IMGTYPE_PNG) {
         $img_r = imagecreatefrompng($src);
     } else {
         $img_r = imagecreatefromjpeg($src);
     }
     $dst_r = ImageCreateTrueColor(Input::get('w'), Input::get('h'));
     imagecopyresampled($dst_r, $img_r, 0, 0, Input::get('x'), Input::get('y'), Input::get('w'), Input::get('h'), Input::get('w'), Input::get('h'));
     $filename = $basepath . 'crop_' . $id;
     imagejpeg($dst_r, $filename, $jpeg_quality);
     $image = ImageModel::createImageModel('crop_' . $id);
     try {
         $session = Session::get('user');
         $userService = new SoapClient(Config::get('wsdl.user'));
         $currentUser = $userService->getUserById(array("userId" => $session['data']->id));
         $currentUser = $currentUser->user;
         $currentUser->avatar = $image;
         $result = $userService->updateUser(array("user" => $currentUser));
         // Cleanup
         File::delete($src);
         File::delete($filename);
         File::delete($basepath . $id);
         return Response::json($result->complete);
     } catch (Exception $ex) {
         error_log($ex);
     }
 }
Example #19
0
 function cleanImg($filename) {
   try { $this->is_valid_image($filename,'png'); } catch (Exception $e) { throw $e; }
   $img = imagecreatefrompng($filename);
   $out = ImageCreateTrueColor(imagesx($img),imagesy($img)) or die('Problem In Creating image');
   //work through the image pixel by pixel
   for ($x = 0; $x < imagesx($img); $x++) {
     for ($y = 0; $y < imagesy($img); $y++) {
       $src_pix = imagecolorat($img,$x,$y);
       try {
         $pix_rgb = $this->rgb_to_array($src_pix);
       } catch (Exception $e) {
         throw $e;
       }
       if ($pix_rgb[0] > 180 && $pix_rgb[1] > 180 && $pix_rgb[2] > 180) {
         //do nothing
       } elseif ($pix_rgb[0] == 69 && $pix_rgb[1] == 41 && $pix_rgb[2] == 36) {
         $pix_rgb = array(255,255,255);
       } elseif ($pix_rgb[1] != 255) {
         $pix_rgb = array(0,0,0);
       }
 
 
       imagesetpixel($out, $x, $y, imagecolorallocate($out, $pix_rgb[0], $pix_rgb[1], $pix_rgb[2]));
     }
   }
 
   //$elements = explode('.', $filename);
   //unlink($filename);
   $imgname = str_replace(".png", ".jpg", $filename);
   imagejpeg($out, $imgname ); 
   imagedestroy($img);
   imagedestroy($out);
   //print_r(get_defined_vars());die();
   return $imgname;
 }
 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;
 }
Example #21
0
 function createthumb($name, $filename, $new_w, $new_h)
 {
     $extention = pathinfo($name, PATHINFO_EXTENSION);
     if (preg_match('/jpg|jpeg/', $extention)) {
         $src_img = imagecreatefromjpeg($name);
     }
     if (preg_match('/png/', $extention)) {
         $src_img = imagecreatefrompng($name);
     }
     $old_x = imageSX($src_img);
     $old_y = imageSY($src_img);
     if ($old_x > $old_y) {
         $thumb_w = $new_w;
         $thumb_h = $old_y * ($new_h / $old_x);
     }
     if ($old_x < $old_y) {
         $thumb_w = $old_x * ($new_w / $old_y);
         $thumb_h = $new_h;
     }
     if ($old_x == $old_y) {
         $thumb_w = $new_w;
         $thumb_h = $new_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);
     if (preg_match("/png/", $extention)) {
         imagepng($dst_img, $filename);
     } else {
         imagejpeg($dst_img, $filename);
     }
     imagedestroy($dst_img);
     imagedestroy($src_img);
 }
Example #22
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 #23
0
function createImage($name, $filename, $new_w, $new_h)
{
    $system2 = explode('.', strtolower(basename($filename)));
    $system2[1] = $system2[1];
    $src_img = imagecreatefromstring(readFileData($name));
    $old_w = imageSX($src_img);
    $old_h = imageSY($src_img);
    $thumb_w = $new_w;
    $thumb_h = $new_h;
    if ($new_w > $old_w) {
        $thumb_w = $old_w;
        $thumb_h = $thumb_w / $old_w * $old_h;
    } else {
        $thumb_w = $new_w;
        $thumb_h = $thumb_w / $old_w * $old_h;
    }
    if ($thumb_h > $new_h) {
        $thumb_h = $new_h;
        $thumb_w = $thumb_h / $old_h * $old_w;
    }
    $dst_img = ImageCreateTrueColor($thumb_w, $thumb_h);
    imagealphablending($dst_img, false);
    imagesavealpha($dst_img, true);
    $transparent = imagecolorallocatealpha($dst_img, 255, 255, 255, 127);
    imagefilledrectangle($dst_img, 0, 0, $thumb_w, $thumb_h, $transparent);
    imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_w, $old_h);
    if (preg_match("/png/", $system2[1])) {
        imagepng($dst_img, $filename);
    } else {
        imagejpeg($dst_img, $filename, 90);
    }
    imagedestroy($dst_img);
    imagedestroy($src_img);
}
Example #24
0
 /**
  * cuts the given png or jpeg picture with coordination and its full path on host server
  *
  * @param object $img
  * $img->name contains name of resource/image
  * $img->mimeType contains mime type of resource/image
  * $img->coords its a object which holds the beginnings of the crop section
  * and height and width of the crop section within itself
  * $img->coords->x1 , $img->coords->y1 , $img->coords->h , $img->coords->w
  */
 public static function cutIt($img)
 {
     /**
      * Image::saveImage dependencies
      */
     $img_quality = 90;
     /**
      * loads a resource from host
      * @see Image::createImage
      */
     $img_r = Image::createImage($img->mimeType, $img->path);
     $img->quality = $img_quality;
     /**
      * creating an image in ram to put our cropped image into it
      */
     $dst_r = ImageCreateTrueColor($img->coords->w, $img->coords->h);
     $img->imgRes = $dst_r;
     /**
      * doing crop in here using $coords , $img_r ,$dst_r and ...
      */
     imagecopyresampled($dst_r, $img_r, 0, 0, $img->coords->x1, $img->coords->y1, $img->coords->w, $img->coords->h, $img->coords->w, $img->coords->h);
     /**
      * saving the result to the host
      */
     Image::saveImage($img);
 }
Example #25
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 #26
0
function crop_image($img, $pw, $ph, $cw, $ch, $x, $y, $targ, $qualigy, $dir, $childdir = null, $filename = null)
{
    $startX = (int) round($pw / $cw * $x);
    $startY = (int) round($ph / $ch * $y);
    //
    if (isset($filename) && !empty($filename)) {
        $picName = $filename . '.jpg';
    } else {
        $picName = time() . '.jpg';
    }
    if (is_dir('./Uploads/' . $dir)) {
        $d = './Uploads/' . $dir . '/';
        $path = '/Uploads/' . $dir . '/';
    } else {
        mkdir('./Uploads/' . $dir);
        $d = './Uploads/' . $dir . '/';
        $path = '/Uploads/' . $dir . '/';
    }
    if (isset($childdir) && !empty($childdir)) {
        if (is_dir('./Uploads/' . $dir . '/' . $childdir)) {
            $d = './Uploads/' . $dir . '/' . $childdir . '/';
            $path = '/Uploads/' . $dir . '/' . $childdir . '/';
        } else {
            mkdir('./Uploads/' . $dir . '/' . $childdir);
            $d = './Uploads/' . $dir . '/' . $childdir . '/';
            $path = '/Uploads/' . $dir . '/' . $childdir . '/';
        }
    }
    $jpeg_quality = $qualigy;
    $src = '.' . $img;
    $imgSize = getimagesize($src);
    switch ($imgSize['mime']) {
        case 'image/jpeg':
            $img_r = imagecreatefromjpeg($src);
            break;
        case 'image/png':
            $img_r = imagecreatefrompng($src);
            break;
        case 'image/gif':
            $img_r = imagecreatefromgif($src);
            break;
        default:
            return array('status' => 'error', 'errorType' => 'extensions', 'Info' => '图片格式错误。');
            exit;
            break;
    }
    $dst_r = ImageCreateTrueColor($targ, $targ);
    $cropImg = ImageCreateTrueColor($pw, $ph);
    imagecopyresampled($cropImg, $img_r, 0, 0, 0, 0, $pw, $ph, $imgSize[0], $imgSize[1]);
    imagecopy($dst_r, $cropImg, 0, 0, $startX, $startY, $targ, $targ);
    imagejpeg($dst_r, $d . $picName, $jpeg_quality);
    imagedestroy($dst_r);
    imagedestroy($cropImg);
    imagedestroy($img_r);
    if (file_exists($d . $picName)) {
        return $path . $picName;
    } else {
        return false;
    }
}
Example #27
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;
 }
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;
}
function createthumb($originalImage, $new_w, $new_h)
{
    $src_img = imagecreatefromjpeg("uploads/" . $originalImage);
    # Add the _t to our image name
    list($imageName, $extension) = explode(".", $originalImage);
    $newName = $imageName . "_t." . $extension;
    # Maintain proportions
    $old_x = imageSX($src_img);
    $old_y = imageSY($src_img);
    if ($old_x > $old_y) {
        $thumb_w = $new_w;
        $thumb_h = $old_y * ($new_h / $old_x);
    }
    if ($old_x < $old_y) {
        $thumb_w = $old_x * ($new_w / $old_y);
        $thumb_h = $new_h;
    }
    if ($old_x == $old_y) {
        $thumb_w = $new_w;
        $thumb_h = $new_h;
    }
    # Create destination-image-resource
    $dst_img = ImageCreateTrueColor($thumb_w, $thumb_h);
    # Copy source-image-resource to destination-image-resource
    imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y);
    # Create the final image from the destination-image-resource
    imagejpeg($dst_img, "uploads/" . $newName);
    # Delete our image-resources
    imagedestroy($dst_img);
    imagedestroy($src_img);
    # Show results
    return $newName;
}
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!";
     }
 }