Example #1
0
function gerar_tumbs_real($t_x, $t_y, $qualidade, $c_original, $c_final)
{
    $thumbnail = imagecreatetruecolor($t_x, $t_y);
    $original = $c_original;
    $igInfo = getImageSize($c_original);
    switch ($igInfo['mime']) {
        case 'image/gif':
            if (imagetypes() & IMG_GIF) {
                $originalimage = imageCreateFromGIF($original);
            } else {
                $ermsg = MSG_GIF_NOT_COMPATIBLE . '<br />';
            }
            break;
        case 'image/jpeg':
            if (imagetypes() & IMG_JPG) {
                $originalimage = imageCreateFromJPEG($original);
            } else {
                $ermsg = MSG_JPG_NOT_COMPATIBLE . '<br />';
            }
            break;
        case 'image/png':
            if (imagetypes() & IMG_PNG) {
                $originalimage = imageCreateFromPNG($original);
            } else {
                $ermsg = MSG_PNG_NOT_COMPATIBLE . '<br />';
            }
            break;
        case 'image/wbmp':
            if (imagetypes() & IMG_WBMP) {
                $originalimage = imageCreateFromWBMP($original);
            } else {
                $ermsg = MSG_WBMP_NOT_COMPATIBLE . '<br />';
            }
            break;
        default:
            $ermsg = $igInfo['mime'] . MSG_FORMAT_NOT_COMPATIBLE . '<br />';
            break;
    }
    $nLargura = $igInfo[0];
    $nAltura = $igInfo[1];
    if ($nLargura > $t_x and $nAltura > $t_y) {
        if ($t_x <= $t_y) {
            $nLargura = (int) ($igInfo[0] * $t_y / $igInfo[1]);
            $nAltura = $t_y;
        } else {
            $nLargura = $t_x;
            $nAltura = (int) ($igInfo[1] * $t_x / $igInfo[0]);
            if ($nAltura < $t_y) {
                $nLargura = (int) ($igInfo[0] * $t_y / $igInfo[1]);
                $nAltura = $t_y;
            }
        }
    }
    $x_pos = $t_x / 2 - $nLargura / 2;
    $y_pos = $t_y / 2 - $nAltura / 2;
    imagecopyresampled($thumbnail, $originalimage, $x_pos, $y_pos, 0, 0, $nLargura, $nAltura, $igInfo[0], $igInfo[1]);
    imagejpeg($thumbnail, $c_final, $qualidade);
    imagedestroy($thumbnail);
    return 'ok';
}
Example #2
0
function create_thumb($path, $thumb_path, $width = THUMB_WIDTH, $height = THUMB_HEIGHT)
{
    $image_info = getImageSize($path);
    // see EXIF for faster way
    switch ($image_info['mime']) {
        case 'image/gif':
            if (imagetypes() & IMG_GIF) {
                // not the same as IMAGETYPE
                $o_im = @imageCreateFromGIF($path);
            } else {
                throw new Exception('GIF images are not supported');
            }
            break;
        case 'image/jpeg':
            if (imagetypes() & IMG_JPG) {
                $o_im = @imageCreateFromJPEG($path);
            } else {
                throw new Exception('JPEG images are not supported');
            }
            break;
        case 'image/png':
            if (imagetypes() & IMG_PNG) {
                $o_im = @imageCreateFromPNG($path);
            } else {
                throw new Exception('PNG images are not supported');
            }
            break;
        case 'image/wbmp':
            if (imagetypes() & IMG_WBMP) {
                $o_im = @imageCreateFromWBMP($path);
            } else {
                throw new Exception('WBMP images are not supported');
            }
            break;
        default:
            throw new Exception($image_info['mime'] . ' images are not supported');
            break;
    }
    list($o_wd, $o_ht, $html_dimension_string) = $image_info;
    $ratio = $o_wd / $o_ht;
    $t_ht = $width;
    $t_wd = $height;
    if (1 > $ratio) {
        $t_wd = round($o_wd * $t_wd / $o_ht);
    } else {
        $t_ht = round($o_ht * $t_ht / $o_wd);
    }
    $t_wd = $t_wd < 1 ? 1 : $t_wd;
    $t_ht = $t_ht < 1 ? 1 : $t_ht;
    $t_im = imageCreateTrueColor($t_wd, $t_ht);
    imageCopyResampled($t_im, $o_im, 0, 0, 0, 0, $t_wd, $t_ht, $o_wd, $o_ht);
    imagejpeg($t_im, $thumb_path, 85);
    chmod($thumb_path, 0664);
    imageDestroy($o_im);
    imageDestroy($t_im);
    return array($t_wd, $t_ht);
}
 function imageConverter()
 {
     /* parse arguments */
     $numargs = func_num_args();
     $imagefile = func_get_arg(0);
     $convertedtype = func_get_arg(1);
     $output = 0;
     if ($numargs > 2) {
         $this->output = func_get_arg(2);
     }
     /* ask the type of original file */
     $fileinfo = pathinfo($imagefile);
     $imtype = $fileinfo["extension"];
     $this->imname = basename($fileinfo["basename"], "." . $imtype);
     $this->imtype = $imtype;
     /* create the image variable of original file */
     switch ($imtype) {
         case "gif":
             $this->im = imageCreateFromGIF($imagefile);
             break;
         case "jpg":
             $this->im = imageCreateFromJPEG($imagefile);
             break;
         case "png":
             $this->im = imageCreateFromPNG($imagefile);
             break;
         case "wbmp":
             $this->im = imageCreateFromWBMP($imagefile);
             break;
             /*
             		mail me if you have/find this functionality bellow  */
             /*
             case "swf":
             	$this->im 	= $this->imageCreateFromSWF($imagefile);
             	break;
             */
     }
     /* convert to intended type */
     $this->convertImage($convertedtype);
 }
Example #4
0
 /**
  * Open the source and target image for processing it
  *
  * @param Asido_TMP &$tmp
  * @return boolean
  * @access protected
  */
 function __open(&$tmp)
 {
     $error_source = false;
     $error_target = false;
     // get image dimensions
     //
     if ($i = @getImageSize($tmp->source_filename)) {
         $tmp->image_width = $i[0];
         $tmp->image_height = $i[1];
     }
     // image type ?
     //
     switch (@$i[2]) {
         case 1:
             // GIF
             $error_source = false == ($tmp->source = @imageCreateFromGIF($tmp->source_filename));
             $error_target = false == ($tmp->target = imageCreateTrueColor($tmp->image_width, $tmp->image_height));
             $error_target &= imageCopyResampled($tmp->target, $tmp->source, 0, 0, 0, 0, $tmp->image_width, $tmp->image_height, $tmp->image_width, $tmp->image_height);
             break;
         case 2:
             // JPG
             $error_source = false == ($tmp->source = imageCreateFromJPEG($tmp->source_filename));
             $error_target = false == ($tmp->target = imageCreateFromJPEG($tmp->source_filename));
             break;
         case 3:
             // PNG
             $error_source = false == ($tmp->source = @imageCreateFromPNG($tmp->source_filename));
             $error_target = false == ($tmp->target = @imageCreateFromPNG($tmp->source_filename));
             break;
         case 15:
             // WBMP
             $error_source = false == ($tmp->source = @imageCreateFromWBMP($tmp->source_filename));
             $error_target = false == ($tmp->target = @imageCreateFromWBMP($tmp->source_filename));
             break;
         case 16:
             // XBM
             $error_source = false == ($tmp->source = @imageCreateFromXBM($tmp->source_filename));
             $error_target = false == ($tmp->target = @imageCreateFromXBM($tmp->source_filename));
             break;
         case 4:
             // SWF
         // SWF
         case 5:
             // PSD
         // PSD
         case 6:
             // BMP
         // BMP
         case 7:
             // TIFF(intel byte order)
         // TIFF(intel byte order)
         case 8:
             // TIFF(motorola byte order)
         // TIFF(motorola byte order)
         case 9:
             // JPC
         // JPC
         case 10:
             // JP2
         // JP2
         case 11:
             // JPX
         // JPX
         case 12:
             // JB2
         // JB2
         case 13:
             // SWC
         // SWC
         case 14:
             // IFF
         // IFF
         default:
             $error_source = false == ($tmp->source = @imageCreateFromString(file_get_contents($tmp->source_filename)));
             $error_target = false == ($tmp->source = @imageCreateFromString(file_get_contents($tmp->source_filename)));
             break;
     }
     return !($error_source || $error_target);
 }
Example #5
0
 public static function thumbComplete($o_file, $fileName, $t_ht = 100, $x, $y, $width, $height, $ow, $sizes = array())
 {
     $image_info = getImageSize($o_file);
     // see EXIF for faster way
     switch ($image_info['mime']) {
         case 'image/gif':
             if (imagetypes() & IMG_GIF) {
                 // not the same as IMAGETYPE
                 $o_im = imageCreateFromGIF($o_file);
             }
             break;
         case 'image/jpeg':
             if (imagetypes() & IMG_JPG) {
                 $o_im = imageCreateFromJPEG($o_file);
             }
             break;
         case 'image/png':
             if (imagetypes() & IMG_PNG) {
                 $o_im = imageCreateFromPNG($o_file);
             }
             break;
         case 'image/wbmp':
             if (imagetypes() & IMG_WBMP) {
                 $o_im = imageCreateFromWBMP($o_file);
             }
             break;
         default:
             break;
     }
     $o_wd = imagesx($o_im);
     $o_ht = imagesy($o_im);
     $size = $o_wd / $ow;
     echo $size . '<br>';
     echo $x * $size . '<br>';
     echo $y * $size . '<br>';
     echo $sizes['width'] . '<br>';
     echo $sizes['height'] . '<br>';
     echo $width * $size . '<br>';
     echo $height * $size . '<br>';
     //        die;
     $new_im = imageCreateTrueColor($width, $height);
     if (empty($sizes)) {
         imagecopyresampled($new_im, $o_im, 0, 0, $x * $size, $y * $size, $width * $size, $height * $size, $width * $size, $height * $size);
     } else {
         imagecopyresampled($new_im, $o_im, 0, 0, $x * $size, $y * $size, $sizes['width'], $sizes['height'], $width * $size, $height * $size);
     }
     imageJPEG($new_im, $fileName, 100);
     chmod($fileName, 0777);
     imageDestroy($o_im);
     imageDestroy($new_im);
     return true;
 }
Example #6
0
 public function MakeThumbnail($o_file, $fileName, $quality, $width, $height)
 {
     $image_info = getImageSize($o_file);
     switch ($image_info['mime']) {
         case 'image/gif':
             if (imagetypes() & IMG_GIF) {
                 // not the same as IMAGETYPE
                 $o_im = imageCreateFromGIF($o_file);
             }
             break;
         case 'image/jpeg':
             if (imagetypes() & IMG_JPG) {
                 $o_im = imageCreateFromJPEG($o_file);
             }
             break;
         case 'image/png':
             if (imagetypes() & IMG_PNG) {
                 $o_im = imageCreateFromPNG($o_file);
             }
             break;
         case 'image/wbmp':
             if (imagetypes() & IMG_WBMP) {
                 $o_im = imageCreateFromWBMP($o_file);
             }
             break;
         default:
             break;
     }
     $o_wd = imagesx($o_im);
     $o_ht = imagesy($o_im);
     // thumbnail width = target * original width / original height
     if ($o_ht > $o_wd) {
         $t_wd = round($o_wd * $height / $o_ht);
         $t_ht = $height;
     }
     if ($o_ht < $o_wd) {
         $t_ht = round($o_ht * $width / $o_wd);
         $t_wd = $width;
     }
     if ($t_ht > $height) {
         $t_wd = round($o_wd * $height / $o_ht);
         $t_ht = $height;
     }
     $t_im = imageCreateTrueColor($t_wd, $t_ht);
     imageCopyResampled($t_im, $o_im, 0, 0, 0, 0, $t_wd, $t_ht, $o_wd, $o_ht);
     imageJPEG($t_im, $fileName, 100);
     imageDestroy($o_im);
     imageDestroy($t_im);
     return true;
 }
function makeThumbnail($o_file, $t_file, $t_ht = 100)
{
    $image_info = getImageSize($o_file);
    // see EXIF for faster way
    switch ($image_info['mime']) {
        case 'image/gif':
            if (imagetypes() & IMG_GIF) {
                // not the same as IMAGETYPE
                $o_im = imageCreateFromGIF($o_file);
            } else {
                $ermsg = 'GIF images are not supported<br />';
            }
            break;
        case 'image/jpeg':
            if (imagetypes() & IMG_JPG) {
                $o_im = imageCreateFromJPEG($o_file);
            } else {
                $ermsg = 'JPEG images are not supported<br />';
            }
            break;
        case 'image/png':
            if (imagetypes() & IMG_PNG) {
                $o_im = imageCreateFromPNG($o_file);
            } else {
                $ermsg = 'PNG images are not supported<br />';
            }
            break;
        case 'image/wbmp':
            if (imagetypes() & IMG_WBMP) {
                $o_im = imageCreateFromWBMP($o_file);
            } else {
                $ermsg = 'WBMP images are not supported<br />';
            }
            break;
        default:
            $ermsg = $image_info['mime'] . ' images are not supported<br />';
            break;
    }
    if (!isset($ermsg)) {
        $o_wd = imagesx($o_im);
        $o_ht = imagesy($o_im);
        // thumbnail width = target * original width / original height
        //
        if ($o_ht > $o_wd && $o_ht > $t_ht) {
            $new_w = $t_ht / $o_ht * $o_wd;
            $new_h = $t_ht;
        } else {
            if ($o_wd > $t_ht) {
                $new_h = $t_ht / $o_wd * $o_ht;
                $new_w = $t_ht;
            } else {
                $new_h = $o_ht;
                $new_w = $o_wd;
            }
        }
        //
        //$t_wd = round($o_wd * $t_ht / $o_ht) ;
        $t_im = imageCreateTrueColor($new_w, $new_h);
        imageCopyResampled($t_im, $o_im, 0, 0, 0, 0, $new_w, $new_h, $o_wd, $o_ht);
        imageJPEG($t_im, $t_file);
        imageDestroy($o_im);
        imageDestroy($t_im);
    }
    return isset($ermsg) ? $ermsg : NULL;
}
        if (imagetypes() & IMG_JPG) {
            $insert2 = imageCreateFromJPEG($foto);
        } else {
            $ermsg = 'JPEG images are not supported<br />';
        }
        break;
    case 'image/png':
        if (imagetypes() & IMG_PNG) {
            $insert2 = imageCreateFromPNG($foto);
        } else {
            $ermsg = 'PNG images are not supported<br />';
        }
        break;
    case 'image/wbmp':
        if (imagetypes() & IMG_WBMP) {
            $insert2 = imageCreateFromWBMP($foto);
        } else {
            $ermsg = 'WBMP images are not supported<br />';
        }
        break;
    default:
        $ermsg = $image_info['mime'] . ' images are not supported<br />';
        break;
}
imagealphablending($insert, false);
imagesavealpha($insert, true);
imagecolortransparent($insert, imagecolorat($insert, 0, 0));
imagecolortransparent($insert2, imagecolorat($insert2, 0, 0));
$insert_x = imagesx($insert);
$insert_y = imagesy($insert);
$is = imagesx($insert2);
Example #9
0
 /**
  * Function image_resize_local will resize the target image
  * @param string $source
  * @param string $dest
  * @param int $targetHeight
  * @param int $targetWidth
  * @return string
  */
 function image_resize_local($source, $dest, $targetHeight = 75, $targetWidth = 100)
 {
     $image_info = @getImageSize($source);
     // see EXIF for faster way
     switch ($image_info['mime']) {
         case 'image/gif':
             if (imagetypes() & IMG_GIF) {
                 $src_handle = imageCreateFromGIF($source);
             } else {
                 $ermsg = 'GIF images are not supported<br />';
             }
             break;
         case 'image/jpeg':
             if (imagetypes() & IMG_JPG) {
                 $src_handle = imageCreateFromJPEG($source);
             } else {
                 $ermsg = 'JPEG images are not supported<br />';
             }
             break;
         case 'image/png':
             if (imagetypes() & IMG_PNG) {
                 $src_handle = imageCreateFromPNG($source);
             } else {
                 $ermsg = 'PNG images are not supported<br />';
             }
             break;
         case 'image/wbmp':
             if (imagetypes() & IMG_WBMP) {
                 $src_handle = imageCreateFromWBMP($source);
             } else {
                 $ermsg = 'WBMP images are not supported<br />';
             }
             break;
         default:
             $ermsg = $image_info['mime'] . ' images are not supported<br />';
             break;
     }
     if (!isset($ermsg)) {
         $org_w = imagesx($src_handle);
         $org_h = imagesy($src_handle);
         $width = $org_w;
         $height = $org_h;
         $arrDimentions = clsUtil::fnSetImageHeighWidth($source, $targetHeight, $targetWidth);
         $dest_handle = imageCreateTrueColor($arrDimentions['width'], $arrDimentions['height']);
         imageCopyResampled($dest_handle, $src_handle, 0, 0, 0, 0, $arrDimentions['width'], $arrDimentions['height'], $org_w, $org_h);
         imageJPEG($dest_handle, $dest);
         imageDestroy($src_handle);
         imageDestroy($dest_handle);
     }
     return isset($ermsg) ? $ermsg : NULL;
 }
/**
 * upload image to destination folder, return file name
 * @author ivan lubis
 * @param $source_pic array string source file
 * @param $destination_folder string destination upload folder
 * @param $filename string file name
 * @param $max_width string maximum image width
 * @param $max_height string maximum image height
 * @return array string of edited file name
 */
function image_arr_resize_to_folder($source_pic, $destination_folder, $filename, $max_width, $max_height)
{
    $tmp_dest = $destination_folder;
    for ($index = 0; $index < count($source_pic['tmp_name']); $index++) {
        $destination_folder = $tmp_dest;
        $image_info = getimagesize($source_pic['tmp_name'][$index]);
        $source_pic_name = $source_pic['name'][$index];
        $source_pic_tmpname = $source_pic['tmp_name'][$index];
        $source_pic_size = $source_pic['size'][$index];
        $source_pic_width = $image_info[0];
        $source_pic_height = $image_info[1];
        $x_ratio = $max_width / $source_pic_width;
        $y_ratio = $max_height / $source_pic_height;
        if ($source_pic_width <= $max_width && $source_pic_height <= $max_height) {
            $tn_width = $source_pic_width;
            $tn_height = $source_pic_height;
        } elseif ($x_ratio * $source_pic_height < $max_height) {
            $tn_height = ceil($x_ratio * $source_pic_height);
            $tn_width = $max_width;
        } else {
            $tn_width = ceil($y_ratio * $source_pic_width);
            $tn_height = $max_height;
        }
        switch ($image_info['mime']) {
            case 'image/gif':
                if (imagetypes() & IMG_GIF) {
                    $src = imageCreateFromGIF($source_pic['tmp_name'][$index]);
                    $destination_folder .= "{$filename[$index]}.gif";
                    $namafile = "{$filename[$index]}.gif";
                }
                break;
            case 'image/jpeg':
                if (imagetypes() & IMG_JPG) {
                    $src = imageCreateFromJPEG($source_pic['tmp_name'][$index]);
                    $destination_folder .= "{$filename[$index]}.jpg";
                    $namafile = "{$filename[$index]}.jpg";
                }
                break;
            case 'image/pjpeg':
                if (imagetypes() & IMG_JPG) {
                    $src = imageCreateFromJPEG($source_pic['tmp_name'][$index]);
                    $destination_folder .= "{$filename[$index]}.jpg";
                    $namafile = "{$filename[$index]}.jpg";
                }
                break;
            case 'image/png':
                if (imagetypes() & IMG_PNG) {
                    $src = imageCreateFromPNG($source_pic['tmp_name'][$index]);
                    $destination_folder .= "{$filename[$index]}.png";
                    $namafile = "{$filename[$index]}.png";
                }
                break;
            case 'image/wbmp':
                if (imagetypes() & IMG_WBMP) {
                    $src = imageCreateFromWBMP($source_pic['tmp_name'][$index]);
                    $destination_folder .= "{$filename[$index]}.bmp";
                    $namafile = "{$filename[$index]}.bmp";
                }
                break;
        }
        //chmod($destination_pic,0777);
        $tmp = imagecreatetruecolor($tn_width, $tn_height);
        imagecopyresampled($tmp, $src, 0, 0, 0, 0, $tn_width, $tn_height, $source_pic_width, $source_pic_height);
        //**** 100 is the quality settings, values range from 0-100.
        switch ($image_info['mime']) {
            case 'image/jpeg':
                imagejpeg($tmp, $destination_folder, 100);
                break;
            case 'image/gif':
                imagegif($tmp, $destination_folder, 100);
                break;
            case 'image/png':
                imagepng($tmp, $destination_folder);
                break;
            default:
                imagejpeg($tmp, $destination_folder, 100);
                break;
        }
        $url[] = $namafile;
    }
    return $url;
}
 /**
  * Creates a thumbnail of the image passed and saves it to $thumbnail
  * Thumbnail uses either width or height, whichever is larger in the original, and then maintains aspect ratio
  *
  * @param string $original path and filename of original/uploaded image
  * @param string $thumbnail location to store thumbnail image
  * @param integer $width
  * @param integer $height
  * @param integer $quality
  */
 protected function CreateThumbnail($original, $thumbnail, $width, $height, $quality)
 {
     list($width_orig, $height_orig) = getimagesize($original);
     if ($width && $width_orig < $height_orig) {
         $width = $height / $height_orig * $width_orig;
     } else {
         $height = $width / $width_orig * $height_orig;
     }
     $image_p = imagecreatetruecolor($width, $height);
     switch ($this->strType) {
         case 'image/gif':
             $image = imageCreateFromGIF($original);
             break;
         case 'image/jpeg':
         case 'image/pjpeg':
             $image = imageCreateFromJPEG($original);
             break;
         case 'image/png':
         case 'image/x-png':
             $image = imageCreateFromPNG($original);
             break;
         case 'image/wbmp':
             $image = imageCreateFromWBMP($original);
             break;
     }
     imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
     imagejpeg($image_p, $thumbnail, $quality);
 }
Example #12
0
 protected function typeCreateImage($pointer)
 {
     $filename = $this->image[$pointer];
     $mime = $this->mime[$pointer];
     if (imagetypes() & $mime) {
         switch ($mime) {
             case 2:
                 return imageCreateFromJPEG($filename);
                 break;
             case 15:
                 return imageCreateFromWBMP($filename);
                 break;
             case 1:
                 return imageCreateFromGIF($filename);
                 break;
             case 3:
                 return imageCreateFromPNG($filename);
                 break;
             case 16:
                 return imageCreateFromXBM($filename);
                 break;
         }
     } else {
         return false;
     }
 }
Example #13
0
function avatar_resize($infile, $outfile, $size)
{
    $image_info = getImageSize($infile);
    switch ($image_info['mime']) {
        case 'image/gif':
            if (imagetypes() & IMG_GIF) {
                $src_img = imageCreateFromGIF($infile);
            } else {
                $ermsg = 'GIF images are not supported<br />';
            }
            break;
        case 'image/jpeg':
            if (imagetypes() & IMG_JPG) {
                $src_img = imageCreateFromJPEG($infile);
            } else {
                $ermsg = 'JPEG images are not supported<br />';
            }
            break;
        case 'image/png':
            if (imagetypes() & IMG_PNG) {
                $src_img = imageCreateFromPNG($infile);
            } else {
                $ermsg = 'PNG images are not supported<br />';
            }
            break;
        case 'image/wbmp':
            if (imagetypes() & IMG_WBMP) {
                $src_img = imageCreateFromWBMP($infile);
            } else {
                $ermsg = 'WBMP images are not supported<br />';
            }
            break;
        default:
            $ermsg = $image_info['mime'] . ' images are not supported<br />';
            break;
    }
    if (isset($ermsg)) {
        echo "Error: {$ermsg}";
        die;
    }
    $dst_img = ImageCreateTrueColor($size, $size);
    imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $size, $size, imagesx($src_img), imagesy($src_img));
    imagejpeg($dst_img, $outfile, 85);
}
Example #14
0
 private function resizeImage_gd($cacheFileName, $width, $height, $crop = false, $cropOffset = 1, $forceSize = false, $usePiramidalSizes = true, $resize = true)
 {
     $objImg = null;
     if (file_exists($this->getFileName())) {
         $imagetype = $this->getOriginalImageType();
         switch ($imagetype) {
             case 'image/gif':
                 if (function_exists('imageCreateFromGIF')) {
                     $objImg = imageCreateFromGIF($this->getFileName());
                 } else {
                     $objImg = imageCreateFromPNG($this->getFileName());
                 }
                 break;
             case 'image/jpeg':
                 $objImg = imageCreateFromJPEG($this->getFileName());
                 break;
             case 'image/png':
                 $objImg = imageCreateFromPNG($this->getFileName());
                 break;
             case 'image/vnd.wap.wbmp':
                 $objImg = imageCreateFromWBMP($this->getFileName());
                 break;
             default:
                 //	$ermsg = $imageInfo['mime'].' images are not supported<br />';
                 break;
         }
     }
     $originalSizes = $this->getOriginalSizes();
     if (!is_null($objImg)) {
         $finalSizes = $this->resizeImageGetFinalSizes($width, $height, $crop, $cropOffset, $forceSize);
         $img = imageCreateTrueColor($crop ? $width : $finalSizes['width'], $crop ? $height : $finalSizes['height']);
         $w = imagecolorallocate($img, 255, 255, 255);
         imagefill($img, 0, 0, $w);
         if ($resize) {
             imageCopyResampled($img, $objImg, $finalSizes['cropX'], $finalSizes['cropY'], 0, 0, $finalSizes['width'], $finalSizes['height'], $originalSizes['width'], $originalSizes['height']);
             $unsharpMask = __Config::get('glizy.media.image.unsharpMask');
             if ($unsharpMask) {
                 list($a, $r, $t) = explode(',', $unsharpMask);
                 glz_importLib('phpUnsharpMask/phpUnsharpMask.php');
                 phpUnsharpMask::applyUnsharpMask($img, $a, $r, $t);
             }
         } else {
             imageCopy($img, $objImg, 0, 0, 0, 0, $originalSizes['width'], $originalSizes['height']);
         }
         if ($this->watermark) {
             $this->insertWatermark($img, $crop ? $width : $finalSizes['width'], $crop ? $height : $finalSizes['height'], 'gd', false);
         }
         imageJPEG($img, $cacheFileName, org_glizy_Config::get('JPG_COMPRESSION'));
         imageDestroy($objImg);
         imageDestroy($img);
         unset($objImg);
         unset($img);
         @touch($cacheFileName, filemtime($this->getFileName()));
         @chmod($cacheFileName, 0777);
         $retInfo = array('imageType' => IMG_JPG, 'fileName' => $cacheFileName, 'width' => $crop ? $width : $finalSizes['width'], 'height' => $crop ? $height : $finalSizes['height'], 'originalWidth' => $originalSizes['width'], 'originalHeight' => $originalSizes['height']);
     } else {
         $fileName = org_glizy_Assets::get('ICON_MEDIA_IMAGE');
         list($width, $height, $imagetypes) = getImageSize($fileName);
         $retInfo = array('imageType' => IMG_GIF, 'fileName' => $fileName, 'width' => $width, 'height' => $height, 'originalWidth' => $width, 'originalHeight' => $height);
     }
     return $retInfo;
 }
Example #15
0
 function init_watermark($sWatermarkFilename, $hPosition = 'right', $vPosition = 'bottom', $edgePadding = 15, $bMakeSourceWatermark = true)
 {
     $size = getimagesize($sWatermarkFilename);
     switch ($size[2]) {
         case IMAGETYPE_GIF:
             $this->img["wm"] = imageCreateFromGIF($sWatermarkFilename);
             break;
         case IMAGETYPE_JPEG:
             $this->img["wm"] = imageCreateFromJPEG($sWatermarkFilename);
             break;
         case IMAGETYPE_PNG:
             $this->img["wm"] = imageCreateFromPNG($sWatermarkFilename);
             break;
         case IMAGETYPE_WBMP:
             $this->img["wm"] = imageCreateFromWBMP($sWatermarkFilename);
             break;
         default:
             return;
     }
     $this->img["wm_width"] = $size[0];
     $this->img["wm_height"] = $size[1];
     $this->img["wm_h_pos"] = $hPosition;
     $this->img["wm_v_pos"] = $vPosition;
     $this->img["wm_padding"] = $edgePadding;
     //накладываем watermark на файл ($this->sSourcePath2file)
     //на тот случай если bSaveAsOriginal (тогда оригинал уже будет с watermark)
     if ($bMakeSourceWatermark) {
         $this->img["only_src"] = imageCreateTrueColor($this->img["width"], $this->img["height"]);
         ImageCopy($this->img["only_src"], $this->img["src"], 0, 0, 0, 0, $this->img["width"], $this->img["height"]);
         $this->make_watermark("only_src", $this->img["width"], $this->img["height"]);
         switch ($this->img['format']) {
             case IMAGETYPE_GIF:
                 imageGIF($this->img["only_src"], $this->sSourcePath2file);
                 break;
             case IMAGETYPE_JPEG:
                 imageJPEG($this->img["only_src"], $this->sSourcePath2file, $this->img["quality"]);
                 break;
             case IMAGETYPE_PNG:
                 imagePNG($this->img["only_src"], $this->sSourcePath2file);
                 break;
             case IMAGETYPE_WBMP:
                 imageWBMP($this->img["only_src"], $this->sSourcePath2file);
                 break;
         }
         imageDestroy($this->img["only_src"]);
     }
 }
Example #16
0
 /**
  * Инициализация водяного знака. Если $sWatermark - не файл, то печатается введенный там текст  
  * 
  * @param mixed $sWatermark водяной знак
  * @param mixed $hPosition позиция по горизонтали
  * @param mixed $vPosition позиция по вертикали
  * @param mixed $xPadding отступ от края по oX 
  * @param mixed $yPadding отступ от края по oY 
  * @param mixed $bMakeSourceWatermark флаг, ставить ли знак на оригинале изображения
  */
 private function init_watermark($sWatermark, $hPosition = 'right', $vPosition = 'bottom', $xPadding = 15, $yPadding = 15, $bMakeSourceWatermark = true)
 {
     if (!$this->oImg['watermark_resizeable']) {
         $this->oImg['coef_width'] = 1;
         $this->oImg['coef_height'] = 1;
     }
     if (file_exists($sWatermark)) {
         if ($this->checkIsImage($sWatermark)) {
             //если watermark с таким путем не кэширован, то создается, иначе - берется из кэша
             if (!isset($this->aWatermarkSources[$sWatermark])) {
                 $size = getimagesize($sWatermark);
                 $this->aWatermarkSources[$sWatermark]['width'] = $size[0];
                 $this->aWatermarkSources[$sWatermark]['height'] = $size[1];
                 switch ($size[2]) {
                     case IMAGETYPE_GIF:
                         $this->aWatermarkSources[$sWatermark]['src'] = imageCreateFromGIF($sWatermark);
                         break;
                     case IMAGETYPE_JPEG:
                         $this->aWatermarkSources[$sWatermark]['src'] = imageCreateFromJPEG($sWatermark);
                         break;
                     case IMAGETYPE_PNG:
                         $this->aWatermarkSources[$sWatermark]['src'] = imageCreateFromPNG($sWatermark);
                         break;
                     case IMAGETYPE_WBMP:
                         $this->aWatermarkSources[$sWatermark]['src'] = imageCreateFromWBMP($sWatermark);
                         break;
                     default:
                         return;
                 }
             }
             // определяем нужные размеры wm исходя из коэффициентов
             if ($this->oImg['watermark_resizeable']) {
                 $nCoef = $this->oImg['coef_width'] > $this->oImg['coef_height'] ? $this->oImg['coef_height'] : $this->oImg['coef_width'];
                 $dst_width = intval($this->aWatermarkSources[$sWatermark]['width'] * $nCoef);
                 $dst_height = intval($this->aWatermarkSources[$sWatermark]['height'] * $nCoef);
             } else {
                 $dst_width = $this->aWatermarkSources[$sWatermark]['width'];
                 $dst_height = $this->aWatermarkSources[$sWatermark]['height'];
             }
             $this->oImg['wm'] = imagecreatetruecolor($dst_width, $dst_height);
             ImageAlphaBlending($this->oImg['wm'], false);
             ImageSaveAlpha($this->oImg['wm'], true);
             imagecopyresized($this->oImg['wm'], $this->aWatermarkSources[$sWatermark]['src'], 0, 0, 0, 0, $dst_width, $dst_height, $this->aWatermarkSources[$sWatermark]['width'], $this->aWatermarkSources[$sWatermark]['height']);
             $this->oImg['wm_width'] = $dst_width;
             $this->oImg['wm_height'] = $dst_height;
             $this->oImg['watermark_pos_x'] = $hPosition;
             $this->oImg['watermark_pos_y'] = $vPosition;
             $this->oImg['watermark_padding_h'] = intval($xPadding * $this->oImg['coef_width']);
             $this->oImg['watermark_padding_v'] = intval($yPadding * $this->oImg['coef_height']);
         } else {
             unset($this->oImg['wm']);
             $this->errors->set('watermark_src_isnt_image');
         }
     } else {
         $nCoef = $this->oImg['coef_width'] > $this->oImg['coef_height'] ? $this->oImg['coef_height'] : $this->oImg['coef_width'];
         $nFontSize = round($this->oImg['watermark_font_size'] * $nCoef);
         $nFontSize = round($nFontSize / 1.333);
         //определение координат нужного прямоугольника под WM
         $aImageDimmention = imagettfbbox($nFontSize, 0, $this->sFontDir . $this->oImg['watermark_font'], $sWatermark);
         //ширина (разница по oX между нижними левым и правым углом прямоугольника)
         $nImgWidth = $aImageDimmention[4] - $aImageDimmention[6];
         //высота (разница по oY между левыми верхним и нижним углом прямоугольника)
         $nImgHeight = $aImageDimmention[1] - $aImageDimmention[7];
         if (!$nImgHeight) {
             $this->errors->set('no_language_support');
             $this->oImg['wm'] = false;
         }
         if ($this->errors->no()) {
             $nImgHeight *= 1.6;
             //небольшое увеличение высоты чтобы поместились выступающие края букв
             $this->oImg['wm'] = ImageCreateTrueColor($nImgWidth, $nImgHeight);
             if ($this->oImg['type'] == IMAGETYPE_GIF) {
                 //Определяем индекс прозрачного цвета у gif
                 $colorcount = imagecolorstotal($this->oImg['src']);
                 imagetruecolortopalette($this->oImg['wm'], true, $colorcount);
                 imagepalettecopy($this->oImg['wm'], $this->oImg['wm']);
                 $trans = imagecolortransparent($this->oImg['wm']);
                 imagefill($this->oImg['wm'], 0, 0, $trans);
                 imagecolortransparent($this->oImg['wm'], $trans);
                 $textcolor = imagecolorallocate($this->oImg['wm'], (int) ($this->oImg['watermark_font_color'] % 0x1000000 / 0x10000), (int) ($this->oImg['watermark_font_color'] % 0x10000 / 0x100), $this->oImg['watermark_font_color'] % 0x100);
             } else {
                 //Определяем индекс прозрачного цвета у png
                 $opacity = imagecolorallocatealpha($this->oImg['wm'], 255, 255, 255, 127);
                 imagefill($this->oImg['wm'], 0, 0, $opacity);
                 ImageAlphaBlending($this->oImg['wm'], false);
                 ImageSaveAlpha($this->oImg['wm'], true);
                 $textcolor = imagecolorallocatealpha($this->oImg['wm'], (int) ($this->oImg['watermark_font_color'] % 0x1000000 / 0x10000), (int) ($this->oImg['watermark_font_color'] % 0x10000 / 0x100), $this->oImg['watermark_font_color'] % 0x100, 0);
             }
             // Наносим текст
             imagettftext($this->oImg['wm'], $nFontSize, 0, 0, intval($nImgHeight * 0.8), $textcolor, $this->sFontDir . $this->oImg['watermark_font'], $sWatermark);
             $this->oImg['wm_width'] = $nImgWidth;
             $this->oImg['wm_height'] = $nImgHeight;
             $this->oImg['watermark_pos_x'] = $hPosition;
             $this->oImg['watermark_pos_y'] = $vPosition;
             $this->oImg['watermark_padding_h'] = intval($xPadding * $this->oImg['coef_width']);
             $this->oImg['watermark_padding_v'] = intval($yPadding * $this->oImg['coef_height']);
         }
     }
     // нанесение wm на оригинал
     if ($bMakeSourceWatermark) {
         $this->oImg['only_src'] = imageCreateTrueColor($this->oImg['orig_width'], $this->oImg['orig_height']);
         ImageCopy($this->oImg['only_src'], $this->oImg['src'], 0, 0, 0, 0, $this->oImg['orig_width'], $this->oImg['orig_height']);
         $this->make_watermark($this->oImg['only_src'], intval($this->oImg['orig_width']), intval($this->oImg['orig_height']));
         switch ($this->oImg['format']) {
             case IMAGETYPE_GIF:
                 imageGIF($this->oImg['only_src'], $this->oImg['orig_filename']);
                 break;
             case IMAGETYPE_JPEG:
                 imageJPEG($this->oImg['only_src'], $this->{$this}->oImg['orig_filename'], $this->oImg['quality']);
                 break;
             case IMAGETYPE_PNG:
                 imagePNG($this->oImg['only_src'], $this->{$this}->oImg['orig_filename']);
                 break;
             case IMAGETYPE_WBMP:
                 imageWBMP($this->oImg['only_src'], $this->{$this}->oImg['orig_filename']);
                 break;
         }
         imageDestroy($this->oImg['only_src']);
     }
 }