예제 #1
1
파일: image.php 프로젝트: nyan-cat/easyweb
 static function load($filename)
 {
     $info = getimagesize($filename);
     list($width, $height) = $info;
     if (!$width || !$height) {
         return null;
     }
     $image = null;
     switch ($info['mime']) {
         case 'image/gif':
             $image = imagecreatefromgif($filename);
             break;
         case 'image/jpeg':
             $image = imagecreatefromjpeg($filename);
             break;
         case 'image/png':
             $image = imagecreatetruecolor($width, $height);
             $white = imagecolorallocate($image, 255, 255, 255);
             imagefill($image, 0, 0, $white);
             $png = imagecreatefrompng($filename);
             imagealphablending($png, true);
             imagesavealpha($png, true);
             imagecopy($image, $png, 0, 0, 0, 0, $width, $height);
             imagedestroy($png);
             break;
     }
     if ($image) {
         return new image($image, $width, $height);
     } else {
         return null;
     }
 }
예제 #2
0
 /**
  * @param $text
  * @return resource
  */
 private function createImage($text)
 {
     if (!is_string($text) || trim($text) == '') {
         $text = 'ERROR';
     }
     // Create an image from captchaBackground.png
     $image = imagecreatefrompng(realpath('bundles/comun/images/captchaBackground.png'));
     // Set the font colour
     $colour = imagecolorallocate($image, 183, 178, 152);
     // Set the font
     //$font = '../fonts/Anorexia.ttf';
     $font = realpath('bundles/comun/fonts/Anorexia.ttf');
     // Set a random integer for the rotation between -15 and 15 degrees
     $rotate = rand(-15, 15);
     // Create an image using our original image and adding the detail
     imagettftext($image, 14, $rotate, 18, 30, $colour, $font, $text);
     // Output the image as a png
     //imagepng($image);
     /*return new Response(
           $captchaText,
           200,
           array(
               'Content-Type' => 'image/png',
               'Cache-Control' => 'no-cache'
           )
       );*/
     return $image;
 }
예제 #3
0
function upload($tmp, $name, $nome, $larguraP, $pasta)
{
    $ext = strtolower(end(explode('.', $name)));
    if ($ext == 'jpg') {
        $img = imagecreatefromjpeg($tmp);
    } elseif ($ext == 'gif') {
        $img = imagecreatefromgif($tmp);
    } else {
        $img = imagecreatefrompng($tmp);
    }
    $x = imagesx($img);
    $y = imagesy($img);
    $largura = $x > $larguraP ? $larguraP : $x;
    $altura = $largura * $y / $x;
    if ($altura > $larguraP) {
        $altura = $larguraP;
        $largura = $altura * $x / $y;
    }
    $nova = imagecreatetruecolor($largura, $altura);
    imagecopyresampled($nova, $img, 0, 0, 0, 0, $largura, $altura, $x, $y);
    imagejpeg($nova, "{$pasta}/{$nome}");
    imagedestroy($img);
    imagedestroy($nova);
    return $nome;
}
예제 #4
0
 /**
  * Load an image
  *
  * @param $filename
  * @return Image
  * @throws Exception
  */
 public static function load($filename)
 {
     $instance = new self();
     // Require GD library
     if (!extension_loaded('gd')) {
         throw new Exception('Required extension GD is not loaded.');
     }
     $instance->filename = $filename;
     $info = getimagesize($instance->filename);
     switch ($info['mime']) {
         case 'image/gif':
             $instance->image = imagecreatefromgif($instance->filename);
             break;
         case 'image/jpeg':
             $instance->image = imagecreatefromjpeg($instance->filename);
             break;
         case 'image/png':
             $instance->image = imagecreatefrompng($instance->filename);
             imagesavealpha($instance->image, true);
             imagealphablending($instance->image, true);
             break;
         default:
             throw new Exception('Invalid image: ' . $instance->filename);
             break;
     }
     $instance->original_info = array('width' => $info[0], 'height' => $info[1], 'orientation' => $instance->get_orientation(), 'exif' => function_exists('exif_read_data') ? $instance->exif = @exif_read_data($instance->filename) : null, 'format' => preg_replace('/^image\\//', '', $info['mime']), 'mime' => $info['mime']);
     $instance->width = $info[0];
     $instance->height = $info[1];
     imagesavealpha($instance->image, true);
     imagealphablending($instance->image, true);
     return $instance;
 }
예제 #5
0
function resize($photo_src, $width, $name)
{
    $parametr = getimagesize($photo_src);
    list($width_orig, $height_orig) = getimagesize($photo_src);
    $ratio_orig = $width_orig / $height_orig;
    $new_width = $width;
    $new_height = $width / $ratio_orig;
    $newpic = imagecreatetruecolor($new_width, $new_height);
    $col2 = imagecolorallocate($newpic, 255, 255, 255);
    imagefilledrectangle($newpic, 0, 0, $new_width, $new_width, $col2);
    switch ($parametr[2]) {
        case 1:
            $image = imagecreatefromgif($photo_src);
            break;
        case 2:
            $image = imagecreatefromjpeg($photo_src);
            break;
        case 3:
            $image = imagecreatefrompng($photo_src);
            break;
    }
    imagecopyresampled($newpic, $image, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
    imagejpeg($newpic, $name, 100);
    return true;
}
예제 #6
0
function foundation_process_image_file($file_name, $setting_name)
{
    if ($setting_name->domain == FOUNDATION_SETTING_DOMAIN && $setting_name->name == 'logo_image') {
        // Need to make sure this isn't too big
        if (function_exists('getimagesize') && function_exists('imagecreatefrompng') && function_exists('imagecopyresampled') && function_exists('imagepng')) {
            $size = getimagesize($file_name);
            if ($size) {
                $width = $size[0];
                $height = $size[1];
                if ($size['mime'] == 'image/png') {
                    if ($width > FOUNDATION_MAX_LOGO_SIZE) {
                        $new_width = FOUNDATION_MAX_LOGO_SIZE;
                        $new_height = $height * $new_width / $width;
                        $src_image = imagecreatefrompng($file_name);
                        $saved_image = imagecreatetruecolor($new_width, $new_height);
                        // Preserve Transparency
                        imagecolortransparent($saved_image, imagecolorallocate($saved_image, 0, 0, 0));
                        imagecopyresampled($saved_image, $src_image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
                        // Get rid of the old file
                        unlink($file_name);
                        // New image, compression level 5 (make it a bit smaller)
                        imagepng($saved_image, $file_name, 5);
                    }
                }
            }
        }
    }
}
예제 #7
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);
     }
 }
예제 #8
0
파일: Image.php 프로젝트: hayate/hayate
 public function __construct($filepath)
 {
     if (!function_exists('gd_info')) {
         throw new Hayate_Exception(_('GD extension is missing.'));
     }
     if (!is_file($filepath)) {
         throw new Hayate_Exception(sprintf(_('Cannot find %s'), $filepath));
     }
     $this->filepath = $filepath;
     $info = getimagesize($this->filepath);
     if (false === $info) {
         throw new Hayate_Exception(sprintf(_('Cannot read %s'), $filepath));
     }
     list($this->width, $this->height) = $info;
     $mimes = array('image/jpeg' => 'jpg', 'image/pjpeg' => 'jpg', 'image/gif' => 'gif', 'image/png' => 'png');
     $this->ext = isset($mimes[$info['mime']]) ? $mimes[$info['mime']] : null;
     if (null === $this->ext) {
         throw new Hayate_Exception(sprintf(_('Supported mime types are: %s'), implode(',', array_keys($mimes))));
     }
     switch ($this->ext) {
         case 'jpg':
             $this->img = imagecreatefromjpeg($filepath);
             break;
         case 'gif':
             $this->img = imagecreatefromgif($filepath);
             break;
         case 'png':
             $this->img = imagecreatefrompng($filepath);
             break;
     }
 }
예제 #9
0
function create_pic($upfile, $new_path, $width)
{
    $quality = 100;
    $image_path = $upfile;
    $image_info = getimagesize($image_path);
    $exname = '';
    //1  =  GIF,  2  =  JPG,  3  =  PNG,  4  =  SWF,  5  =  PSD,  6  =  BMP,  7  =  TIFF(intel  byte  order),  8  =  TIFF(motorola  byte  order),  9  =  JPC,  10  =  JP2,  11  =  JPX,  12  =  JB2,  13  =  SWC,  14  =  IFF
    switch ($image_info[2]) {
        case 1:
            @($image = imagecreatefromgif($image_path));
            $exname = 'gif';
            break;
        case 2:
            @($image = imagecreatefromjpeg($image_path));
            $exname = 'jpg';
            break;
        case 3:
            @($image = imagecreatefrompng($image_path));
            $exname = 'png';
            break;
        case 6:
            @($image = imagecreatefromwbmp($image_path));
            $exname = 'wbmp';
            break;
    }
    $T_width = $image_info[0];
    $T_height = $image_info[1];
    if (!empty($image)) {
        $image_x = imagesx($image);
        $image_y = imagesy($image);
    } else {
        return FALSE;
    }
    @chmod($new_path, 0777);
    if ($image_x > $width) {
        $x = $width;
        $y = intval($x * $image_y / $image_x);
    } else {
        @copy($image_path, $new_path . '.' . $exname);
        return $exname;
    }
    $newimage = imagecreatetruecolor($x, $y);
    imagecopyresampled($newimage, $image, 0, 0, 0, 0, $x, $y, $image_x, $image_y);
    switch ($image_info[2]) {
        case 1:
            imagegif($newimage, $new_path . '.gif', $quality);
            break;
        case 2:
            imagejpeg($newimage, $new_path . '.jpg', $quality);
            break;
        case 3:
            imagepng($newimage, $new_path . '.png', $quality);
            break;
        case 6:
            imagewbmp($newimage, $new_path . '.wbmp', $quality);
            break;
    }
    imagedestroy($newimage);
    return $exname;
}
예제 #10
0
 public static function image($item, $path, $filename)
 {
     $image_tempname1 = $_FILES[$item]['name'];
     $ImageName = $path . $image_tempname1;
     $newfilename = $path . $filename;
     if (move_uploaded_file($_FILES[$item]['tmp_name'], $ImageName)) {
         list($width, $height, $type, $attr) = getimagesize($ImageName);
         if ($type == 2) {
             rename($ImageName, $newfilename);
         } else {
             if ($type == 1) {
                 $image_old = imagecreatefromgif($ImageName);
             } elseif ($type == 3) {
                 $image_old = imagecreatefrompng($ImageName);
             }
             $image_jpg = imagecreatetruecolor($width, $height);
             imagecopyresampled($image_jpg, $image_old, 0, 0, 0, 0, $width, $height, $width, $height);
             imagejpeg($image_jpg, $newfilename);
             imagedestroy($image_old);
             imagedestroy($image_jpg);
         }
         return 1;
     } else {
         return 0;
     }
 }
예제 #11
0
 /**
  * Set the image variable by using image create
  *
  * @param string $filename - The image filename
  */
 private function setImage($filename)
 {
     $size = getimagesize($filename);
     $this->ext = $size['mime'];
     switch ($this->ext) {
         // Image is a JPG
         case 'image/jpg':
         case 'image/jpeg':
             // create a jpeg extension
             $this->image = imagecreatefromjpeg($filename);
             break;
             // Image is a GIF
         // Image is a GIF
         case 'image/gif':
             $this->image = @imagecreatefromgif($filename);
             break;
             // Image is a PNG
         // Image is a PNG
         case 'image/png':
             $this->image = @imagecreatefrompng($filename);
             break;
             // Mime type not found
         // Mime type not found
         default:
             throw new Exception("File is not an image, please use another file type.", 1);
     }
     $this->origWidth = imagesx($this->image);
     $this->origHeight = imagesy($this->image);
 }
예제 #12
0
 static function resizewidth($width, $imageold, $imagenew)
 {
     $image_info = getimagesize($imageold);
     $image_type = $image_info[2];
     if ($image_type == IMAGETYPE_JPEG) {
         $image = imagecreatefromjpeg($imageold);
     } elseif ($this->image_type == IMAGETYPE_GIF) {
         $image = imagecreatefromgif($imageold);
     } elseif ($this->image_type == IMAGETYPE_PNG) {
         $image = imagecreatefrompng($imageold);
     }
     $ratio = imagesy($image) / imagesx($image);
     $height = $width * $ratio;
     //$width = imagesx($image) * $width/100;
     // $height = imagesx($image) * $width/100;
     $new_image = imagecreatetruecolor($width, $height);
     imagecopyresampled($new_image, $image, 0, 0, 0, 0, $width, $height, $image_info[0], $image_info[1]);
     $image = $new_image;
     $compression = 75;
     $permissions = null;
     if ($image_type == IMAGETYPE_JPEG) {
         imagejpeg($image, $imagenew, $compression);
     } elseif ($image_type == IMAGETYPE_GIF) {
         imagegif($image, $imagenew);
     } elseif ($image_type == IMAGETYPE_PNG) {
         imagepng($image, $imagenew);
     }
     if ($permissions != null) {
         chmod($imagenew, $permissions);
     }
 }
예제 #13
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;
     }
 }
예제 #14
0
function get_image($file)
{
    /*
    	Create a resource from image file and return it with getimagesize() array
    	$file - image file or resource
    	return array('res'=>$image_resource, 'imgsize'=>getimagesize($file))
    */
    if (is_file($file) === true && file_exists($file) === true && is_readable($file) === true) {
        $img_size = getimagesize($file);
        if ($img_size !== false) {
            $im_mime = $img_size['mime'];
            // Get the image from file
            if ($im_mime === 'image/jpeg') {
                $res = imagecreatefromjpeg($file);
            } else {
                if ($im_mime === 'image/gif') {
                    $res = imagecreatefromgif($file);
                } else {
                    if ($im_mime === 'image/png') {
                        $res = imagecreatefrompng($file);
                    } else {
                        // Exit if not supported format
                        return false;
                    }
                }
            }
            return array('res' => $res, 'imgsize' => $img_size);
        }
    }
    return false;
}
예제 #15
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);
 }
예제 #16
0
 private function openImage($file)
 {
     // *** Get extension
     $extension = strtolower(strrchr($file, '.'));
     $file_size = @filesize($file) / 1024 / 1024;
     // magic number convert bytes to mb
     $image_size_limit = 0.5;
     // sorry for the magic numbering... can't get a good read on how to programatically fix this.
     // if we're about to try to load a massive image...
     // don't
     if ($file_size >= $image_size_limit || $file_size == 0) {
         return false;
     }
     switch ($extension) {
         case '.jpg':
         case '.jpeg':
             $img = imagecreatefromjpeg($file);
             break;
         case '.gif':
             $img = @imagecreatefromgif($file);
             break;
         case '.png':
             $img = @imagecreatefrompng($file);
             break;
         default:
             $img = false;
             break;
     }
     return $img;
 }
예제 #17
0
 /**
  * Loads image source and its properties to the instanciated object
  *
  * @param string $filename
  * @return ImageResize
  * @throws \Exception
  */
 public function __construct($filename)
 {
     $image_info = @getimagesize($filename);
     if (!$image_info) {
         throw new \Exception('Could not read file');
     }
     list($this->original_w, $this->original_h, $this->source_type) = $image_info;
     switch ($this->source_type) {
         case IMAGETYPE_GIF:
             $this->source_image = imagecreatefromgif($filename);
             break;
         case IMAGETYPE_JPEG:
             $this->source_image = $this->imageCreateJpegfromExif($filename);
             // set new width and height for image, maybe it has changed
             $this->original_w = ImageSX($this->source_image);
             $this->original_h = ImageSY($this->source_image);
             break;
         case IMAGETYPE_PNG:
             $this->source_image = imagecreatefrompng($filename);
             break;
         default:
             throw new \Exception('Unsupported image type');
             break;
     }
     return $this->resize($this->getSourceWidth(), $this->getSourceHeight());
 }
 /**
  *
  * @param string $playername Minecraft player name
  * @param resource $avatar the rendered avatar (for example player head)
  *
  * @param string $background Image Path or Standard Value
  * @return resource the generated banner
  */
 public static function player($playername, $avatar = NULL, $background = NULL)
 {
     $canvas = MinecraftBanner::getBackgroundCanvas(self::PLAYER_WIDTH, self::PLAYER_HEIGHT, $background);
     $head_height = self::AVATAR_SIZE;
     $head_width = self::AVATAR_SIZE;
     $avater_x = self::PLAYER_PADDING;
     $avater_y = self::PLAYER_HEIGHT / 2 - self::AVATAR_SIZE / 2;
     if ($avatar == NULL) {
         $avatar = imagecreatefrompng(__DIR__ . "/img/head.png");
         imagesavealpha($avatar, true);
         imagecopy($canvas, $avatar, $avater_x, $avater_y, 0, 0, $head_width, $head_height);
     } else {
         $head_width = imagesx($avatar);
         $head_height = imagesy($avatar);
         if ($head_width > self::AVATAR_SIZE) {
             $head_width = self::AVATAR_SIZE;
         }
         if ($head_height > self::AVATAR_SIZE) {
             $head_height = self::AVATAR_SIZE;
         }
         $center_x = $avater_x + self::AVATAR_SIZE / 2 - $head_width / 2;
         $center_y = $avater_y + self::AVATAR_SIZE / 2 - $head_height / 2;
         imagecopy($canvas, $avatar, $center_x, $center_y, 0, 0, $head_width, $head_height);
     }
     $box = imagettfbbox(self::TEXT_SIZE, 0, MinecraftBanner::FONT_FILE, $playername);
     $text_width = abs($box[4] - $box[0]);
     $text_color = imagecolorallocate($canvas, 255, 255, 255);
     $remaining = self::PLAYER_WIDTH - self::AVATAR_SIZE - $avater_x - self::PLAYER_PADDING;
     $text_posX = $avater_x + self::AVATAR_SIZE + $remaining / 2 - $text_width / 2;
     $text_posY = $avater_y + self::AVATAR_SIZE / 2 + self::TEXT_SIZE / 2;
     imagettftext($canvas, self::TEXT_SIZE, 0, $text_posX, $text_posY, $text_color, MinecraftBanner::FONT_FILE, $playername);
     return $canvas;
 }
예제 #19
0
파일: Simple.php 프로젝트: Dulciane/jaws
 /**
  * Displays the captcha image
  *
  * @access  public
  * @param   int     $key    Captcha key
  * @return  mixed   Captcha raw image data
  */
 function image($key)
 {
     $value = Jaws_Utils::RandomText();
     $result = $this->update($key, $value);
     if (Jaws_Error::IsError($result)) {
         $value = '';
     }
     $bg = dirname(__FILE__) . '/resources/simple.bg.png';
     $im = imagecreatefrompng($bg);
     imagecolortransparent($im, imagecolorallocate($im, 255, 255, 255));
     // Write it in a random position..
     $darkgray = imagecolorallocate($im, 0x10, 0x70, 0x70);
     $x = 5;
     $y = 20;
     $text_length = strlen($value);
     for ($i = 0; $i < $text_length; $i++) {
         $fnt = rand(7, 10);
         $y = rand(6, 10);
         imagestring($im, $fnt, $x, $y, $value[$i], $darkgray);
         $x = $x + rand(15, 25);
     }
     header("Content-Type: image/png");
     ob_start();
     imagepng($im);
     $content = ob_get_contents();
     ob_end_clean();
     imagedestroy($im);
     return $content;
 }
 /**
  * MÉTODO CONSTRUTOR
  *
  * @author Gibran
  */
 function Imagem($arquivo)
 {
     if (is_file($arquivo)) {
         $this->Arquivo = $arquivo;
         // OBTÉM OS DADOS DA IMAGEM
         $this->ColecaoDados = getimagesize($this->Arquivo);
         // CARREGA A IMAGEM DE ACORDO COM O TIPO
         switch ($this->ColecaoDados[2]) {
             case 1:
                 $this->Recurso = imagecreatefromgif($this->Arquivo);
                 $this->Tipo = "image/gif";
                 break;
             case 2:
                 $this->Recurso = imagecreatefromjpeg($this->Arquivo);
                 $this->Tipo = "image/jpeg";
                 imageinterlace($this->Recurso, true);
                 break;
             case 3:
                 $this->Recurso = imagecreatefrompng($this->Arquivo);
                 $this->Tipo = "image/png";
                 imagealphablending($this->Recurso, false);
                 imagesavealpha($this->Recurso, true);
                 break;
             default:
                 $this->ColecaoDados = null;
                 $this->Recurso = null;
                 $this->Tipo = null;
                 return null;
                 break;
         }
     } else {
         return null;
     }
 }
예제 #21
0
function cuttingimg($zoom, $fn, $sz)
{
    @mkdir(WUO_ROOT . '/photos/maps');
    $img = imagecreatefrompng(WUO_ROOT . '/photos/maps/0-0-0-' . $fn);
    // получаем идентификатор загруженного изрбражения которое будем резать
    $info = getimagesize(WUO_ROOT . '/photos/maps/0-0-0-' . $fn);
    // получаем в массив информацию об изображении
    $w = $info[0];
    $h = $info[1];
    // ширина и высота исходного изображения
    $sx = round($w / $sz, 0);
    // длинна куска изображения
    $sy = round($h / $sz, 0);
    // высота куска изображения
    $px = 0;
    $py = 0;
    // координаты шага "реза"
    for ($y = 0; $y <= $sz; $y++) {
        for ($x = 0; $x <= $sz; $x++) {
            $imgcropped = imagecreatetruecolor($sx, $sy);
            imagecopy($imgcropped, $img, 0, 0, $px, $py, $sx, $sy);
            imagepng($imgcropped, WUO_ROOT . '/photos/maps/' . $zoom . '-' . $y . '-' . $x . '-' . $fn);
            $px = $px + $sx;
        }
        $px = 0;
        $py = $py + $sy;
    }
}
예제 #22
0
 public function __construct($path)
 {
     if (!file_exists($path)) {
         throw new Exception("Данного файла нет");
     }
     $this->type = $this->getType($path);
     switch ($this->type) {
         case IMAGETYPE_JPEG:
             $img = imagecreatefromjpeg($path);
             break;
         case IMAGETYPE_PNG:
             $img = imagecreatefrompng($path);
             break;
         case IMAGETYPE_PNG:
             $img = imagecreatefrompng($path);
             break;
         case IMAGETYPE_BMP:
             $img = imagecreatefromwbmp($path);
             break;
         default:
             $img = false;
     }
     $this->img = $img;
     if (!$this->img) {
         throw new Exception('Не удалость создать дескриптор изображения');
     }
     $this->width = imagesx($this->img);
     $this->height = imagesy($this->img);
 }
function mkthumb($img_src, $img_width = "100", $img_height = "100", $folder_scr = "include/files", $des_src = "include/files")
{
    // Größe und Typ ermitteln
    list($src_width, $src_height, $src_typ) = getimagesize($folder_scr . "/" . $img_src);
    if (!$src_typ) {
        return false;
    }
    // calculate new size
    if ($src_width >= $src_height) {
        $new_image_height = $src_height / $src_width * $img_width;
        $new_image_width = $img_width;
        if ($new_image_height > $img_height) {
            $new_image_width = $new_image_width / $new_image_height * $img_height;
            $new_image_height = $img_height;
        }
    } else {
        $new_image_width = $src_width / $src_height * $img_height;
        $new_image_height = $img_height;
        if ($new_image_width > $img_width) {
            $new_image_height = $new_image_height / $new_image_width * $img_width;
            $new_image_width = $img_width;
        }
    }
    // for the case that the thumbnail would be bigger then the original picture
    if ($new_image_height > $src_height) {
        $new_image_width = $new_image_width * $src_height / $new_image_height;
        $new_image_height = $src_height;
    }
    if ($new_image_width > $src_width) {
        $new_image_height = $new_image_height * $new_image_width / $src_width;
        $new_image_width = $src_width;
    }
    if ($src_typ == 1) {
        $image = imagecreatefromgif($folder_scr . "/" . $img_src);
        $new_image = imagecreate($new_image_width, $new_image_height);
        imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_image_width, $new_image_height, $src_width, $src_height);
        imagegif($new_image, $des_src . "/" . $img_src . "_thumb", 100);
        imagedestroy($image);
        imagedestroy($new_image);
        return true;
    } elseif ($src_typ == 2) {
        $image = imagecreatefromjpeg($folder_scr . "/" . $img_src);
        $new_image = imagecreatetruecolor($new_image_width, $new_image_height);
        imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_image_width, $new_image_height, $src_width, $src_height);
        imagejpeg($new_image, $des_src . "/" . $img_src . "_thumb", 100);
        imagedestroy($image);
        imagedestroy($new_image);
        return true;
    } elseif ($src_typ == 3) {
        $image = imagecreatefrompng($folder_scr . "/" . $img_src);
        $new_image = imagecreatetruecolor($new_image_width, $new_image_height);
        imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_image_width, $new_image_height, $src_width, $src_height);
        imagepng($new_image, $des_src . "/" . $img_src . "_thumb");
        imagedestroy($image);
        imagedestroy($new_image);
        return true;
    } else {
        return false;
    }
}
예제 #24
0
파일: class_gd.php 프로젝트: Evrika/Vidal
 /** Returns an array. Element 0 - GD resource. Element 1 - width. Element 2 - height.
  * Returns FALSE on failure. The only one parameter $image can be an instance of this class,
  * a GD resource, an array(width, height) or path to image file.
  * @param mixed $image
  * @return array */
 protected function build_image($image)
 {
     if ($image instanceof gd) {
         $width = $image->get_width();
         $height = $image->get_height();
         $image = $image->get_image();
     } elseif (is_resource($image) && get_resource_type($image) == "gd") {
         $width = @imagesx($image);
         $height = @imagesy($image);
     } elseif (is_array($image)) {
         list($key, $width) = each($image);
         list($key, $height) = each($image);
         $image = imagecreatetruecolor($width, $height);
     } elseif (false !== (list($width, $height, $type) = @getimagesize($image))) {
         $image = $type == IMAGETYPE_GIF ? @imagecreatefromgif($image) : ($type == IMAGETYPE_WBMP ? @imagecreatefromwbmp($image) : ($type == IMAGETYPE_JPEG ? @imagecreatefromjpeg($image) : ($type == IMAGETYPE_JPEG2000 ? @imagecreatefromjpeg($image) : ($type == IMAGETYPE_PNG ? imagecreatefrompng($image) : ($type == IMAGETYPE_XBM ? @imagecreatefromxbm($image) : false)))));
         if ($type == IMAGETYPE_PNG) {
             imagealphablending($image, false);
         }
     }
     $return = is_resource($image) && get_resource_type($image) == "gd" && isset($width) && isset($height) && preg_match('/^[1-9][0-9]*$/', $width) !== false && preg_match('/^[1-9][0-9]*$/', $height) !== false ? array($image, $width, $height) : false;
     if ($return !== false && isset($type)) {
         $this->type = $type;
     }
     return $return;
 }
예제 #25
0
파일: helper.php 프로젝트: sansandeep143/av
/**
 *  Retourne la couleur du pixel en bas a gauche de l'image
 **/
function colorImageBottom($imageName)
{
    // recuperer le type et la taille de l'image
    // Pb sur certains JPG qui retourne ''
    list($imgW, $imgH, $imgTyp) = getimagesize($imageName);
    switch ($imgTyp) {
        case 1:
            $im = imagecreatefromgif($imageName);
            break;
        case 2:
        case ' ':
            $im = imagecreatefromjpeg($imageName);
            break;
        case 3:
            $im = imagecreatefrompng($imageName);
            break;
        default:
            $app = JFactory::getApplication();
            $app->enqueueMessage(JTEXT::_('IMGNAME_ERROR') . '[name=' . $imageName . '] [ type=' . $imgTyp . '] [ format= ' . $imgW . 'x' . $imgH, 'error');
            var_dump(gd_info());
            return "";
    }
    $rgb = imagecolorat($im, 2, $imgH - 2);
    $hex = sprintf("%06X", $rgb);
    return $hex;
}
 public function fill_watermark()
 {
     $image = $this->editor->get_image();
     $size = $this->editor->get_size();
     list($mask_width, $mask_height, $mask_type, $mask_attr) = getimagesize($this->args['mask']);
     switch ($mask_type) {
         case 1:
             $mask = imagecreatefromgif($this->args['mask']);
             break;
         case 2:
             $mask = imagecreatefromjpeg($this->args['mask']);
             break;
         case 3:
             $mask = imagecreatefrompng($this->args['mask']);
             break;
     }
     imagealphablending($image, true);
     if (strpos($this->args['position'], 'left') !== false) {
         $left = $this->args['padding'];
     } else {
         $left = $size['width'] - $mask_width - $this->args['padding'];
     }
     if (strpos($this->args['position'], 'top') !== false) {
         $top = $this->args['padding'];
     } else {
         $top = $size['height'] - $mask_height - $this->args['padding'];
     }
     imagecopy($image, $mask, $left, $top, 0, 0, $mask_width, $mask_height);
     $this->editor->update_image($image);
     imagedestroy($mask);
 }
예제 #27
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");
    }
}
예제 #28
-1
파일: gd.php 프로젝트: syjzwjj/quyeba
 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;
 }
예제 #29
-6
function resizer($image)
{
    $name = md5(sha1(date('d-m-y H:i:s') . $image['tmp_name']));
    $type = $image['type'];
    switch ($type) {
        case "image/jpeg":
            $img = imagecreatefromjpeg($image['tmp_name']);
            break;
        case "image/png":
            $img = imagecreatefrompng($image['tmp_name']);
            break;
    }
    $x = imagesx($img);
    $y = imagesy($img);
    $height = 1200 * $y / $x;
    $new = imagecreatetruecolor(1200, $height);
    imagecopyresampled($new, $img, 0, 0, 0, 0, 1200, $height, $x, $y);
    switch ($type) {
        case "image/jpeg":
            $local = "../assets/img/Portfolioimg/{$name}" . ".jpg";
            imagejpeg($new, $local);
            break;
        case "image/png":
            $local = "../assets/img/Portfolioimg/{$name}" . ".png";
            imagejpeg($new, $local);
            break;
    }
    return $local;
}
 /**
  * Contructor method. Will create a new image from the target file.
  * Accepts an image filename as a string. Method also works out how
  * big the image is and stores this in the $image array.
  *
  * @param string $imgFile The image filename.
  */
 public function ImageManipulation($imgfile)
 {
     //detect image format
     $this->image["format"] = preg_replace("/.*\\.(.*)\$/", "\\1", $imgfile);
     //$this->image["format"] = preg_replace(".*\.(.*)$", "\\1", $imgfile);
     $this->image["format"] = strtoupper($this->image["format"]);
     // convert image into usable format.
     if ($this->image["format"] == "JPG" || $this->image["format"] == "JPEG") {
         //JPEG
         $this->image["format"] = "JPEG";
         $this->image["src"] = ImageCreateFromJPEG($imgfile);
     } elseif ($this->image["format"] == "PNG") {
         //PNG
         $this->image["format"] = "PNG";
         $this->image["src"] = imagecreatefrompng($imgfile);
     } elseif ($this->image["format"] == "GIF") {
         //GIF
         $this->image["format"] = "GIF";
         $this->image["src"] = ImageCreateFromGif($imgfile);
     } elseif ($this->image["format"] == "WBMP") {
         //WBMP
         $this->image["format"] = "WBMP";
         $this->image["src"] = ImageCreateFromWBMP($imgfile);
     } else {
         //DEFAULT
         return false;
     }
     // Image is ok
     $this->imageok = true;
     // Work out image size
     $this->image["sizex"] = imagesx($this->image["src"]);
     $this->image["sizey"] = imagesy($this->image["src"]);
 }