コード例 #1
0
function thumbnail($PicPathIn, $PicPathOut, $PicFilenameIn, $PicFilenameOut, $neueHoehe, $Quality)
{
    // Bilddaten ermitteln
    $size = getimagesize("{$PicPathIn}" . "{$PicFilenameIn}");
    $breite = $size[0];
    $hoehe = $size[1];
    $neueBreite = intval($breite * $neueHoehe / $hoehe);
    if ($size[2] == 1) {
        // GIF
        $altesBild = ImageCreateFromGIF("{$PicPathIn}" . "{$PicFilenameIn}");
        $neuesBild = imageCreateTrueColor($neueBreite, $neueHoehe);
        imageCopyResized($neuesBild, $altesBild, 0, 0, 0, 0, $neueBreite, $neueHoehe, $breite, $hoehe);
        imageJPEG($neuesBild, "{$PicPathOut}" . "{$PicFilenameOut}", $Quality);
    }
    if ($size[2] == 2) {
        // JPG
        $altesBild = ImageCreateFromJPEG("{$PicPathIn}" . "{$PicFilenameIn}");
        $neuesBild = imageCreateTrueColor($neueBreite, $neueHoehe);
        imageCopyResized($neuesBild, $altesBild, 0, 0, 0, 0, $neueBreite, $neueHoehe, $breite, $hoehe);
        ImageJPEG($neuesBild, "{$PicPathOut}" . "{$PicFilenameOut}", $Quality);
    }
    if ($size[2] == 3) {
        // PNG
        $altesBild = ImageCreateFromPNG("{$PicPathIn}" . "{$PicFilenameIn}");
        $neuesBild = imageCreateTrueColor($neueBreite, $neueHoehe);
        imageCopyResized($neuesBild, $altesBild, 0, 0, 0, 0, $neueBreite, $neueHoehe, $breite, $hoehe);
        ImageJPEG($neuesBild, "{$PicPathOut}" . "{$PicFilenameOut}", $Quality);
    }
}
コード例 #2
0
ファイル: index.php プロジェクト: nidtropical/nidtropical_old
 function writeCopy($filename, $width, $height) {
          if($this->isLoaded()) {
              $imageNew = imageCreate($width, $height);
              if(!$imageNew) {
                  echo "ERREUR : Nouvelle image non créée";
              }
              imageCopyResized($imageNew, $this->image, 0, 0, 0, 0, $width, $height, $this->width, $this->height);
              imageJpeg($imageNew, $filename);
          }
 }
コード例 #3
0
 function Resize($maxwidth = 10000, $maxheight, $imagename, $filetype, $how = 'keep_aspect')
 {
     $target_temp_file = tempnam("jinn/temp", "gdlib_");
     unlink($target_temp_file);
     $target_temp_file .= '.' . $filetype;
     if (!$maxheight) {
         $maxheight = 10000;
     }
     if (!$maxwidth) {
         $maxwidth = 10000;
     }
     $qual = 100;
     $filename = $imagename;
     $ext = $filetype;
     list($curwidth, $curheight) = getimagesize($filename);
     $factor = min($maxwidth / $curwidth, $maxheight / $curheight);
     $sx = 0;
     $sy = 0;
     $sw = $curwidth;
     $sh = $curheight;
     $dx = 0;
     $dy = 0;
     $dw = $curwidth * $factor;
     $dh = $curheight * $factor;
     if ($ext == "JPEG") {
         $src = ImageCreateFromJPEG($filename);
     }
     if ($ext == "GIF") {
         $src = ImageCreateFromGIF($filename);
     }
     if ($ext == "PNG") {
         $src = ImageCreateFromPNG($filename);
     }
     if (function_exists('ImageCreateTrueColor')) {
         $dst = ImageCreateTrueColor($dw, $dh);
     } else {
         $dst = ImageCreate($dw, $dh);
     }
     if (function_exists('ImageCopyResampled')) {
         imageCopyResampled($dst, $src, $dx, $dy, $sx, $sy, $dw, $dh, $sw, $sh);
     } else {
         imageCopyResized($dst, $src, $dx, $dy, $sx, $sy, $dw, $dh, $sw, $sh);
     }
     if ($ext == "JPEG") {
         ImageJPEG($dst, $target_temp_file, $qual);
     }
     if ($ext == "PNG") {
         ImagePNG($dst, $target_temp_file, $qual);
     }
     if ($ext == "GIF") {
         ImagePNG($dst, $target_temp_file, $qual);
     }
     ImageDestroy($dst);
     return $target_temp_file;
 }
コード例 #4
0
ファイル: profile_image.php プロジェクト: rjdesign/Ilch-1.2
function create_avatar($imgpath, $thumbpath, $neueBreite, $neueHoehe)
{
    $size = getimagesize($imgpath);
    $breite = $size[0];
    $hoehe = $size[1];
    $RatioW = $neueBreite / $breite;
    $RatioH = $neueHoehe / $hoehe;
    if ($RatioW < $RatioH) {
        $neueBreite = $breite * $RatioW;
        $neueHoehe = $hoehe * $RatioW;
    } else {
        $neueBreite = $breite * $RatioH;
        $neueHoehe = $hoehe * $RatioH;
    }
    $neueBreite = round($neueBreite, 0);
    $neueHoehe = round($neueHoehe, 0);
    if (function_exists('gd_info')) {
        $tmp = gd_info();
        $imgsup = $tmp['GIF Create Support'] ? 1 : 2;
        unset($tmp);
    } else {
        $imgsup = 2;
    }
    if ($size[2] < $imgsup or $size[2] > 3) {
        return false;
    }
    if ($size[2] == 1) {
        $altesBild = imagecreatefromgif($imgpath);
    } elseif ($size[2] == 2) {
        $altesBild = imagecreatefromjpeg($imgpath);
    } elseif ($size[2] == 3) {
        $altesBild = imagecreatefrompng($imgpath);
    }
    if (function_exists('imagecreatetruecolor') and $size[2] != 1) {
        $neuesBild = png_create_transparent($neueBreite, $neueHoehe);
        imagecopyresampled($neuesBild, $altesBild, 0, 0, 0, 0, $neueBreite, $neueHoehe, $breite, $hoehe);
    } elseif (function_exists('imagecreatetruecolor') and $size[2] == 1) {
        $neuesBild = imageCreate($neueBreite, $neueHoehe);
        gif_create_transparent($neuesBild, $altesBild);
        imagecopyresampled($neuesBild, $altesBild, 0, 0, 0, 0, $neueBreite, $neueHoehe, $breite, $hoehe);
    } else {
        $neuesBild = imageCreate($neueBreite, $neueHoehe);
        imageCopyResized($neuesBild, $altesBild, 0, 0, 0, 0, $neueBreite, $neueHoehe, $breite, $hoehe);
    }
    if ($size[2] == 1) {
        ImageGIF($neuesBild, $thumbpath);
    } elseif ($size[2] == 2) {
        ImageJPEG($neuesBild, $thumbpath);
    } elseif ($size[2] == 3) {
        ImagePNG($neuesBild, $thumbpath);
    }
    return true;
}
コード例 #5
0
 /**
  * Do the actual resize of an image
  *
  * @param Asido_TMP &$tmp
  * @param integer $width
  * @param integer $height
  * @return boolean
  * @access protected
  */
 function __resize(&$tmp, $width, $height)
 {
     // create new target
     //
     $_ = imageCreateTrueColor($width, $height);
     imageSaveAlpha($_, true);
     imageAlphaBlending($_, false);
     $r = imageCopyResized($_, $tmp->target, 0, 0, 0, 0, $width, $height, $tmp->image_width, $tmp->image_height);
     // set new target
     //
     $this->__destroy_target($tmp);
     $tmp->target = $_;
     return $r;
 }
コード例 #6
0
ファイル: gallery.php プロジェクト: kveldscholten/Ilch-1.1
function create_thumb($imgpath, $thumbpath, $neueBreite)
{
    $size = getimagesize($imgpath);
    $breite = $size[0];
    $hoehe = $size[1];
    $neueHoehe = intval($hoehe * $neueBreite / $breite);
    if (function_exists('gd_info')) {
        $tmp = gd_info();
        $imgsup = $tmp['GIF Create Support'] ? 1 : 2;
        unset($tmp);
    } else {
        $imgsup = 2;
    }
    if ($size[2] < $imgsup or $size[2] > 3) {
        return FALSE;
    }
    if ($size[2] == 1) {
        $altesBild = imagecreatefromgif($imgpath);
    } elseif ($size[2] == 2) {
        $altesBild = imagecreatefromjpeg($imgpath);
    } elseif ($size[2] == 3) {
        $altesBild = imagecreatefrompng($imgpath);
    }
    if (function_exists('imagecreatetruecolor') and $size[2] != 1) {
        $neuesBild = imagecreatetruecolor($neueBreite, $neueHoehe);
        imagecopyresampled($neuesBild, $altesBild, 0, 0, 0, 0, $neueBreite, $neueHoehe, $breite, $hoehe);
    } else {
        $neuesBild = imageCreate($neueBreite, $neueHoehe);
        imageCopyResized($neuesBild, $altesBild, 0, 0, 0, 0, $neueBreite, $neueHoehe, $breite, $hoehe);
    }
    if ($size[2] == 1) {
        ImageGIF($neuesBild, $thumbpath);
    } elseif ($size[2] == 2) {
        ImageJPEG($neuesBild, $thumbpath);
    } elseif ($size[2] == 3) {
        ImagePNG($neuesBild, $thumbpath);
    }
    return TRUE;
}
コード例 #7
0
ファイル: thumbnail.php プロジェクト: jaanusnurmoja/redjoomla
 public function CreatThumb($filetype, $tsrc, $dest, $n_width, $n_height)
 {
     if ($filetype == "gif") {
         $im = ImageCreateFromGIF($dest);
         // Original picture width is stored
         $width = ImageSx($im);
         // Original picture height is stored
         $height = ImageSy($im);
         $newimage = imagecreatetruecolor($n_width, $n_height);
         imageCopyResized($newimage, $im, 0, 0, 0, 0, $n_width, $n_height, $width, $height);
         ImageGIF($newimage, $tsrc);
         chmod("{$tsrc}", 0755);
     }
     if ($filetype == "jpg") {
         $im = ImageCreateFromJPEG($dest);
         // Original picture width is stored
         $width = ImageSx($im);
         // Original picture height is stored
         $height = ImageSy($im);
         $newimage = imagecreatetruecolor($n_width, $n_height);
         imageCopyResized($newimage, $im, 0, 0, 0, 0, $n_width, $n_height, $width, $height);
         ImageJpeg($newimage, $tsrc);
         chmod("{$tsrc}", 0755);
     }
     if ($filetype == "png") {
         $im = ImageCreateFromPNG($dest);
         // Original picture width is stored
         $width = ImageSx($im);
         // Original picture height is stored
         $height = ImageSy($im);
         $newimage = imagecreatetruecolor($n_width, $n_height);
         imageCopyResized($newimage, $im, 0, 0, 0, 0, $n_width, $n_height, $width, $height);
         imagepng($newimage, $tsrc);
         chmod("{$tsrc}", 0755);
     }
 }
コード例 #8
0
ファイル: Image.php プロジェクト: BGCX261/zibo-svn-to-git
 /**
  * Copy an existing internal image resource, or part of it, to this Image instance
  * @param resource existing internal image resource as source for the copy
  * @param int x x-coordinate where the copy starts
  * @param int y y-coordinate where the copy starts
  * @param int resourceX starting x coordinate of the source image resource
  * @param int resourceY starting y coordinate of the source image resource
  * @param int width resulting width of the copy (not of the resulting image)
  * @param int height resulting height of the copy (not of the resulting image)
  * @param int resourceWidth width of the source image resource to copy
  * @param int resourceHeight height of the source image resource to copy
  * @return null
  */
 protected function copyResource($resource, $x, $y, $resourceX, $resourceY, $width, $height, $resourceWidth, $resourceHeight)
 {
     if (!imageCopyResampled($this->resource, $resource, $x, $y, $resourceX, $resourceY, $width, $height, $resourceWidth, $resourceHeight)) {
         if (!imageCopyResized($this->resource, $resource, $x, $y, $resourceX, $resourceY, $width, $height, $resourceWidth, $resourceHeight)) {
             throw new ImageException('Could not copy the image resource');
         }
     }
     $transparent = imageColorAllocate($this->resource, 0, 0, 0);
     imageColorTransparent($this->resource, $transparent);
     $this->width = $width;
     $this->height = $height;
 }
コード例 #9
0
 function geraFotos($fotoOriginal)
 {
     if (!file_exists($fotoOriginal)) {
         return;
     }
     list($imagewidth, $imageheight, $img_type) = @GetImageSize($fotoOriginal);
     $src_img_original = '';
     $fim_largura = $imagewidth;
     $fim_altura = $imageheight;
     $extensao = $img_type == 2 ? '.jpg' : ($img_type == 3 ? '.png' : '');
     $nome_do_arquivo = array_pop(explode('/', $fotoOriginal)) . $extensao;
     $caminhoDaBig = 'arquivos/educar/aluno/big/' . $nome_do_arquivo;
     $caminhoDaFotoOriginal = 'arquivos/educar/aluno/original/' . $nome_do_arquivo;
     if ($imagewidth > 700) {
         $new_w = 700;
         $ratio = $imagewidth / $new_w;
         $new_h = ceil($imageheight / $ratio);
         $fim_largura = $new_w;
         $fim_altura = $new_h;
         if (!file_exists($caminhoDaBig)) {
             if ($img_type == 2) {
                 $src_img_original = @imagecreatefromjpeg($fotoOriginal);
                 $dst_img = @imagecreatetruecolor($new_w, $new_h);
                 imagecopyresized($dst_img, $src_img_original, 0, 0, 0, 0, $new_w, $new_h, imagesx($src_img_original), imagesy($src_img_original));
                 imagejpeg($dst_img, $caminhoDaBig);
             } elseif ($img_type == 3) {
                 $src_img_original = @ImageCreateFrompng($fotoOriginal);
                 $dst_img = @imagecreatetruecolor($new_w, $new_h);
                 ImageCopyResized($dst_img, $src_img_original, 0, 0, 0, 0, $new_w, $new_h, ImageSX($src_img_original), ImageSY($src_img_original));
                 Imagepng($dst_img, $caminhoDaBig);
             }
         }
     } else {
         if (!file_exists($caminhoDaBig)) {
             copy($fotoOriginal, $caminhoDaBig);
             if ($img_type == 2) {
                 $src_img_original = @imagecreatefromjpeg($fotoOriginal);
             } elseif ($img_type == 3) {
                 $src_img_original = @imagecreatefrompng($fotoOriginal);
             }
         }
     }
     $new_w = 100;
     $ratio = $imagewidth / $new_w;
     $new_h = round($imageheight / $ratio);
     $caminhoDaSmall = 'arquivos/educar/aluno/small/' . $nome_do_arquivo;
     if (file_exists($caminhoDaBig)) {
         if ($img_type == 2) {
             $dst_img = @imagecreatetruecolor($new_w, $new_h);
             @imagecopyresized($dst_img, $src_img_original, 0, 0, 0, 0, $new_w, $new_h, imagesx($src_img_original), imagesy($src_img_original));
             @imagejpeg($dst_img, $caminhoDaSmall);
         } elseif ($img_type == 3) {
             $dst_img = @imagecreatetruecolor($new_w, $new_h);
             @imageCopyResized($dst_img, $src_img_original, 0, 0, 0, 0, $new_w, $new_h, ImageSX($src_img_original), imageSY($src_img_original));
             @imagepng($dst_img, $caminhoDaSmall);
         } elseif ($img_type == 1) {
             $dst_img = @imagecreatefromgif($src_img_original);
             @imageCopyResized($dst_img, $src_img_original, 0, 0, 0, 0, $new_w, $new_h, ImageSX($src_img_original), imageSY($src_img_original));
             @imagegif($dst_img, $caminhoDaSmall);
         }
     }
     copy($fotoOriginal, $caminhoDaFotoOriginal);
     if (!(file_exists($fotoOriginal) && file_exists($caminhoDaSmall) && file_exists($caminhoDaBig))) {
         die("<center><br>Um erro ocorreu ao inserir a foto.<br>Por favor tente novamente.</center>");
     }
     if (file_exists($fotoOriginal)) {
         unlink($fotoOriginal);
     }
     return $nome_do_arquivo;
 }
コード例 #10
0
ファイル: resize_img.php プロジェクト: azone/General-Projects
imagefill($im_resized, 0, 0, $white_color);
$old_w = imagesx($im);
$old_h = imagesy($im);
$old_rate = $old_w / $old_h;
if ($old_rate == $new_rate) {
    imageCopyResized($im_resized, $im, 0, 0, 0, 0, $w, $h, $old_w, $old_h);
} else {
    if ($old_w > $old_h) {
        $tmp_h = $h;
        $tmp_w = $tmp_h * $old_rate;
        $tmp_im = imageCreate($tmp_w, $tmp_h);
        $white_color = imagecolorallocate($tmp_im, 255, 255, 255);
        imagefill($tmp_im, 0, 0, $white_color);
        imageCopyResized($tmp_im, $im, 0, 0, 0, 0, $tmp_w, $tmp_h, $old_w, $old_h);
        imageCopyResized($im_resized, $tmp_im, 0, 0, round(($tmp_w - $w) / 2), 0, $w, $h, $w, $h);
        imagedestroy($tmp_im);
    } else {
        $tmp_w = $w;
        $tmp_h = $tmp_w / $old_rate;
        $tmp_im = imageCreate($tmp_w, $tmp_h);
        $white_color = imagecolorallocate($tmp_im, 255, 255, 255);
        imagefill($tmp_im, 0, 0, $white_color);
        imageCopyResized($tmp_im, $im, 0, 0, 0, 0, $tmp_w, $tmp_h, $old_w, $old_h);
        imageCopyResized($im_resized, $tmp_im, 0, 0, 0, round(($tmp_h - $h) / 2), $w, $h, $w, $h);
        imagedestroy($tmp_im);
    }
}
header('Content-Type: image/jpeg');
imagejpeg($im_resized);
imagedestroy($im);
imagedestroy($im_resized);
コード例 #11
0
ファイル: fotos_cad.php プロジェクト: secteofilandia/ieducar
 function Novo()
 {
     global $HTTP_POST_FILES;
     if (!empty($HTTP_POST_FILES['foto']['name'])) {
         $fotoOriginal = "tmp/" . $HTTP_POST_FILES['foto']['name'];
         if (file_exists($fotoOriginal)) {
             unlink($fotoOriginal);
         }
         copy($HTTP_POST_FILES['foto']['tmp_name'], $fotoOriginal);
         list($imagewidth, $imageheight, $img_type) = getImageSize($fotoOriginal);
         $src_img_original = "";
         $fim_largura = $imagewidth;
         $fim_altura = $imageheight;
         $extensao = $img_type == "2" ? ".jpg" : ($img_type == "3" ? ".png" : "");
         $nome_do_arquivo = date('Y-m-d-h-i') . "-" . substr(md5($fotoOriginal), 0, 10) . $extensao;
         $caminhoDaBig = "fotos/big/{$nome_do_arquivo}";
         $caminhoDaSBig = "fotos/sbig/{$nome_do_arquivo}";
         if ($imagewidth > 700 && $imageheight < $imagewidth) {
             $new_w = 500;
             $ratio = $imagewidth / $new_w;
             $new_h = ceil($imageheight / $ratio);
             if (!file_exists($caminhoDaBig)) {
                 if ($img_type == "2") {
                     $src_img_original = imagecreatefromjpeg($fotoOriginal);
                     $dst_img = imagecreatetruecolor($new_w, $new_h);
                     imagecopyresized($dst_img, $src_img_original, 0, 0, 0, 0, $new_w, $new_h, imagesx($src_img_original), imagesy($src_img_original));
                     imagejpeg($dst_img, $caminhoDaBig);
                 } else {
                     if ($img_type == "3") {
                         $src_img_original = @ImageCreateFrompng($fotoOriginal);
                         $dst_img = @imagecreatetruecolor($new_w, $new_h);
                         ImageCopyResized($dst_img, $src_img_original, 0, 0, 0, 0, $new_w, $new_h, ImageSX($src_img_original), ImageSY($src_img_original));
                         Imagepng($dst_img, $caminhoDaBig);
                     }
                 }
             }
         } elseif ($imagewidth > 400 && $imageheight > $imagewidth) {
             $new_w = 400;
             $ratio = $imagewidth / $new_w;
             $new_h = ceil($imageheight / $ratio);
             $fim_largura = $new_w;
             $fim_altura = $new_h;
             if (!file_exists($caminhoDaBig)) {
                 if ($img_type == "2") {
                     $src_img_original = @imagecreatefromjpeg($fotoOriginal);
                     $dst_img = @imagecreatetruecolor($new_w, $new_h);
                     imagecopyresized($dst_img, $src_img_original, 0, 0, 0, 0, $new_w, $new_h, imagesx($src_img_original), imagesy($src_img_original));
                     imagejpeg($dst_img, $caminhoDaBig);
                 } else {
                     if ($img_type == "3") {
                         $src_img_original = @ImageCreateFrompng($fotoOriginal);
                         $dst_img = @imagecreatetruecolor($new_w, $new_h);
                         ImageCopyResized($dst_img, $src_img_original, 0, 0, 0, 0, $new_w, $new_h, ImageSX($src_img_original), ImageSY($src_img_original));
                         Imagepng($dst_img, $caminhoDaBig);
                     }
                 }
             }
         } else {
             if (!file_exists($caminhoDaBig)) {
                 copy($fotoOriginal, $caminhoDaBig);
                 if ($img_type == "2") {
                     $src_img_original = @imagecreatefromjpeg($fotoOriginal);
                 } else {
                     if ($img_type == "3") {
                         $src_img_original = @imagecreatefrompng($fotoOriginal);
                     }
                 }
             }
         }
         $new_w = 100;
         $ratio = $imagewidth / $new_w;
         $new_h = round($imageheight / $ratio);
         $caminhoDaSmall = "fotos/small/{$nome_do_arquivo}";
         if (!file_exists($caminhoDaSmall)) {
             if ($img_type == "2") {
                 $dst_img = @imagecreatetruecolor($new_w, $new_h);
                 @imagecopyresized($dst_img, $src_img_original, 0, 0, 0, 0, $new_w, $new_h, imagesx($src_img_original), imagesy($src_img_original));
                 @imagejpeg($dst_img, $caminhoDaSmall);
             } else {
                 if ($img_type == "3") {
                     $dst_img = @imagecreatetruecolor($new_w, $new_h);
                     @imageCopyResized($dst_img, $src_img_original, 0, 0, 0, 0, $new_w, $new_h, ImageSX($src_img_original), imageSY($src_img_original));
                     @imagepng($dst_img, $caminhoDaSmall);
                 }
             }
         }
         copy($fotoOriginal, $caminhoDaSBig);
         if (!(file_exists($fotoOriginal) && file_exists($caminhoDaSmall) && file_exists($caminhoDaBig))) {
             die("<center><br>Um erro ocorreu ao inserir a foto.<br>Por favor tente novamente.</center>");
         }
     } else {
         return false;
     }
     @session_start();
     $this->id_pessoa = @$_SESSION['id_pessoa'];
     session_write_close();
     $this->data_foto = str_replace("%2F", "/", $this->data_foto);
     $db = new clsBanco();
     $db->Consulta("INSERT INTO foto_portal ( nm_credito, ref_cod_foto_secao, ref_ref_cod_pessoa_fj, data_foto, titulo, descricao, caminho, altura, largura ) VALUES ( '{$this->nm_credito}', '1',  {$this->id_pessoa}, now(), '{$this->titulo}', '{$this->descricao}', '{$nome_do_arquivo}', {$fim_largura}, {$fim_altura} )");
     echo "<script>document.location='fotos_lst.php';</script>";
     return true;
 }
コード例 #12
0
ファイル: index.php プロジェクト: kleopatra999/PHPhoto
/**
* Generate images of alternate sizes.
*/
function resizeImage($cnvrt_arry)
{
    global $platform, $imgs, $cnvrt_path, $reqd_image, $convert_writable, $convert_magick, $convert_GD, $convert_cmd, $cnvrt_alt, $cnvrt_mesgs, $compat_quote;
    if (empty($imgs) || $convert_writable == FALSE) {
        return;
    }
    if ($convert_GD == TRUE && !($gd_version = gdVersion())) {
        return;
    }
    if ($cnvrt_alt['no_prof'] == TRUE) {
        $strip_prof = ' +profile "*"';
    } else {
        $strip_prof = '';
    }
    if ($cnvrt_alt['mesg_on'] == TRUE) {
        $str = '';
    }
    foreach ($imgs as $img_file) {
        if ($cnvrt_alt['indiv'] == TRUE && $img_file != $reqd_image['file']) {
            continue;
        }
        $orig_img = $reqd_image['pwd'] . '/' . $img_file;
        $cnvrtd_img = $cnvrt_path . '/' . $cnvrt_arry['prefix'] . $img_file;
        if (!is_file($cnvrtd_img)) {
            $img_size = GetImageSize($orig_img);
            $height = $img_size[1];
            $width = $img_size[0];
            $area = $height * $width;
            $maxarea = $cnvrt_arry['maxwid'] * $cnvrt_arry['maxwid'] * 0.9;
            $maxheight = $cnvrt_arry['maxwid'] * 0.75 + 1;
            if ($area > $maxarea || $width > $cnvrt_arry['maxwid'] || $height > $maxheight) {
                if ($width / $cnvrt_arry['maxwid'] >= $height / $maxheight) {
                    $dim = 'W';
                }
                if ($height / $maxheight >= $width / $cnvrt_arry['maxwid']) {
                    $dim = 'H';
                }
                if ($dim == 'W') {
                    $cnvt_percent = round(0.9375 * $cnvrt_arry['maxwid'] / $width * 100, 2);
                }
                if ($dim == 'H') {
                    $cnvt_percent = round(0.75 * $cnvrt_arry['maxwid'] / $height * 100, 2);
                }
                // convert it
                if ($convert_magick == TRUE) {
                    // Image Magick image conversion
                    if ($platform == 'Win32' && $compat_quote == TRUE) {
                        $winquote = '"';
                    } else {
                        $winquote = '';
                    }
                    exec($winquote . $convert_cmd . ' -geometry ' . $cnvt_percent . '%' . ' -quality ' . $cnvrt_arry['qual'] . ' -sharpen ' . $cnvrt_arry['sharpen'] . $strip_prof . ' "' . $orig_img . '"' . ' "' . $cnvrtd_img . '"' . $winquote);
                    $using = $cnvrt_mesgs['using IM'];
                } elseif ($convert_GD == TRUE) {
                    // GD image conversion
                    if (eregi('\\.jpg$|\\.jpeg$', $img_file) == TRUE && (imageTypes() & IMG_JPG) == TRUE) {
                        $src_img = imageCreateFromJpeg($orig_img);
                    } elseif (eregi('\\.gif$', $img_file) == TRUE && (imageTypes() & IMG_PNG) == TRUE) {
                        $src_img = imageCreateFromPng($orig_img);
                    } elseif (eregi('\\.gif$', $img_file) == TRUE && (imageTypes() & IMG_GIF) == TRUE) {
                        $src_img = imageCreateFromGif($orig_img);
                    } else {
                        continue;
                    }
                    $src_width = imageSx($src_img);
                    $src_height = imageSy($src_img);
                    $dest_width = $src_width * ($cnvt_percent / 100);
                    $dest_height = $src_height * ($cnvt_percent / 100);
                    if ($gd_version >= 2) {
                        $dst_img = imageCreateTruecolor($dest_width, $dest_height);
                        imageCopyResampled($dst_img, $src_img, 0, 0, 0, 0, $dest_width, $dest_height, $src_width, $src_height);
                    } else {
                        $dst_img = imageCreate($dest_width, $dest_height);
                        imageCopyResized($dst_img, $src_img, 0, 0, 0, 0, $dest_width, $dest_height, $src_width, $src_height);
                    }
                    imageDestroy($src_img);
                    if (eregi('\\.jpg$|\\.jpeg$/i', $img_file) == TRUE && (imageTypes() & IMG_JPG) == TRUE) {
                        imageJpeg($dst_img, $cnvrtd_img, $cnvrt_arry['qual']);
                    } elseif (eregi('\\.gif$', $img_file) == TRUE && (imageTypes() & IMG_PNG) == TRUE) {
                        imagePng($dst_img, $cnvrtd_img);
                    } elseif (eregi('\\.gif$/i', $img_file) == TRUE && (imageTypes() & IMG_GIF) == TRUE) {
                        imageGif($dst_img, $cnvrtd_img);
                    }
                    imageDestroy($dst_img);
                    $using = $cnvrt_mesgs['using GD'] . $gd_version;
                }
                if ($cnvrt_alt['mesg_on'] == TRUE && is_file($cnvrtd_img)) {
                    $str .= "  <small>\n" . '   ' . $cnvrt_mesgs['generated'] . $cnvrt_arry['txt'] . $cnvrt_mesgs['converted'] . $cnvrt_mesgs['image_for'] . $img_file . $using . ".\n" . "  </small>\n  <br />\n";
                }
            }
        }
    }
    if (isset($str)) {
        return $str;
    }
}
コード例 #13
0
 private function make_thumbnails($updir, $img)
 {
     $thumbnail_width = 146;
     $thumbnail_height = 116;
     $thumb_preword = "thumb_";
     $arr_image_details = GetImageSize("{$updir}" . "{$img}");
     $original_width = $arr_image_details[0];
     $original_height = $arr_image_details[1];
     if ($original_width > $original_height) {
         $new_width = $thumbnail_width;
         $new_height = intval($original_height * $new_width / $original_width);
     } else {
         $new_height = $thumbnail_height;
         $new_width = intval($original_width * $new_height / $original_height);
     }
     $dest_x = intval(($thumbnail_width - $new_width) / 2);
     $dest_y = intval(($thumbnail_height - $new_height) / 2);
     if ($arr_image_details[2] == 1) {
         $imgt = "ImageGIF";
         $imgcreatefrom = "ImageCreateFromGIF";
     }
     if ($arr_image_details[2] == 2) {
         $imgt = "ImageJPEG";
         $imgcreatefrom = "ImageCreateFromJPEG";
     }
     if ($arr_image_details[2] == 3) {
         $imgt = "ImagePNG";
         $imgcreatefrom = "ImageCreateFromPNG";
     }
     if ($imgt) {
         $old_image = $imgcreatefrom("{$updir}" . "{$img}");
         $new_image = imagecreatetruecolor($thumbnail_width, $thumbnail_height);
         imageCopyResized($new_image, $old_image, 0, 0, 0, 0, 146, 116, $original_width, $original_height);
         $imgt($new_image, "{$updir}" . "{$thumb_preword}" . "{$img}");
     }
 }
コード例 #14
0
ファイル: GD.php プロジェクト: Abuamany/concerto-platform
 public function border($size, $color)
 {
     if (!$this->_processedImage) {
         return false;
     }
     if (is_array($color)) {
         list($red, $green, $blue) = $color;
     } else {
         list($red, $green, $blue) = PGRThumb_Utils::html2rgb($color);
     }
     $width = $this->_width + 2 * $size;
     $height = $this->_height + 2 * $size;
     $newimage = imagecreatetruecolor($width, $height);
     $border_color = imagecolorallocate($newimage, $red, $green, $blue);
     imagefilledrectangle($newimage, 0, 0, $width, $height, $border_color);
     $res = imageCopyResized($newimage, $this->_processedImage, $size, $size, 0, 0, $this->_width, $this->_height, $this->_width, $this->_height);
     if ($res) {
         $this->_processedImage = $newimage;
     }
     $this->_width = $width;
     $this->_height = $height;
     return $res;
 }
コード例 #15
0
ファイル: basic_functions1.php プロジェクト: Entellus/System
function upMultImageWithThumb($destpath, $thumbPath, $file, $n_width, $n_height)
{
    $path = '';
    while (list($key, $value) = each($_FILES[$file]["name"])) {
        if (!empty($value)) {
            if ($_FILES[$file]["type"][$key] == "image/gif" || $_FILES[$file]["type"][$key] == "image/jpeg" || $_FILES[$file]["type"][$key] == "image/pjpeg" || $_FILES[$file]["type"][$key] == "image/png" && $_FILES[$file]["size"][$key] < 2000000) {
                $source = $_FILES[$file]["tmp_name"][$key];
                $filename = $_FILES[$file]["name"][$key];
                move_uploaded_file($source, $destpath . $filename);
                //echo "Uploaded: " . $destpath . $filename . "<br/>" ;
                $path .= $filename . '***';
                //thumbnail creation start//
                $tsrc = $thumbPath . $_FILES[$file]["name"][$key];
                // Path where thumb nail image will be stored
                //$n_width	=	100;          // Fix the width of the thumb nail images
                //$n_height	=	100;         // Fix the height of the thumb nail imaage
                /////////////////////////////////////////////// Starting of GIF thumb nail creation///////////
                $add = $destpath . $filename;
                if ($_FILES[$file]["type"][$key] == "image/gif") {
                    //echo "hello";
                    $im = ImageCreateFromGIF($add);
                    $width = ImageSx($im);
                    // Original picture width is stored
                    $height = ImageSy($im);
                    // Original picture height is stored
                    $newimage = imagecreatetruecolor($n_width, $n_height);
                    imageCopyResized($newimage, $im, 0, 0, 0, 0, $n_width, $n_height, $width, $height);
                    if (function_exists("imagegif")) {
                        Header("Content-type: image/gif");
                        ImageGIF($newimage, $tsrc);
                    }
                    if (function_exists("imagejpeg")) {
                        Header("Content-type: image/jpeg");
                        ImageJPEG($newimage, $tsrc);
                    }
                }
                //chmod("$tsrc",0777);
                ////////// end of gif file thumb nail creation//////////
                //$n_width=100;          // Fix the width of the thumb nail images
                //$n_height=100;         // Fix the height of the thumb nail imaage
                ////////////// starting of JPG thumb nail creation//////////
                if ($_FILES[$file]["type"][$key] == "image/jpeg") {
                    //echo $_FILES[$file]["name"][$key]."<br>";
                    $im = ImageCreateFromJPEG($add);
                    $width = ImageSx($im);
                    // Original picture width is stored
                    $height = ImageSy($im);
                    // Original picture height is stored
                    $newimage = imagecreatetruecolor($n_width, $n_height);
                    imageCopyResized($newimage, $im, 0, 0, 0, 0, $n_width, $n_height, $width, $height);
                    ImageJpeg($newimage, $tsrc);
                    chmod("{$tsrc}", 0777);
                }
                ////////////////  End of png thumb nail creation //////////
                if ($_FILES[$file]["type"][$key] == "image/png") {
                    //echo "hello";
                    $im = ImageCreateFromPNG($add);
                    $width = ImageSx($im);
                    // Original picture width is stored
                    $height = ImageSy($im);
                    // Original picture height is stored
                    $newimage = imagecreatetruecolor($n_width, $n_height);
                    imageCopyResized($newimage, $im, 0, 0, 0, 0, $n_width, $n_height, $width, $height);
                    if (function_exists("imagepng")) {
                        //Header("Content-type: image/png");
                        ImagePNG($newimage, $tsrc);
                    }
                    if (function_exists("imagejpeg")) {
                        //Header("Content-type: image/jpeg");
                        ImageJPEG($newimage, $tsrc);
                    }
                }
                // thumbnail creation end---
            } else {
                $msg = "error in upload";
                //return $msg;
            }
        }
        //if
    }
    //while
    $cnt = strlen($path) - 3;
    $pathnw = substr_replace($path, '', $cnt, 3);
    return $pathnw;
}
コード例 #16
0
ファイル: index.php プロジェクト: ezchx/skippy
         $n_width = 230;
         if ($n_height > 160) {
             $n_width = $n_width / $n_height * 160;
             $n_height = 160;
         }
     }
     if ($height > 160) {
         $n_width = $width / $height * 160;
         $n_height = 160;
         if ($n_width > 230) {
             $n_height = $n_height / $n_width * 230;
             $n_width = 230;
         }
     }
     $newimage = imagecreatetruecolor($n_width, $n_height);
     imageCopyResized($newimage, $im, 0, 0, 0, 0, $n_width, $n_height, $width, $height);
     ImageJPEG($newimage, $tsrc);
 }
 //		$to = "*****@*****.**"; //
 //		$subject = "***Skippy Alert***"; //
 //		$body = "Somebody just used Skippy the Shoe Finder!"; //
 //		$headers = "From: noreply@skippysearch.com\n"; //
 //		mail($to,$subject,$body,$headers); //
 // Color Select //
 $sample = 100;
 $pig = 32;
 // Get picture height and width //
 $im = imagecreatefromjpeg($tsrc);
 $width = ImageSx($im);
 $height = ImageSy($im);
 $winc = round($width / sqrt($sample / ($height / $width)));
コード例 #17
0
ファイル: acoes_foto.php プロジェクト: secteofilandia/ieducar
 function geraFotos($fotoOriginal)
 {
     list($imagewidth, $imageheight, $img_type) = @GetImageSize($fotoOriginal);
     $src_img_original = "";
     $fim_largura = $imagewidth;
     $fim_altura = $imageheight;
     $extensao = $img_type == "2" ? ".jpg" : ($img_type == "3" ? ".png" : "");
     $nome_do_arquivo = array_pop(explode("/", $fotoOriginal));
     //date('Y-m-d')."-".substr(md5($fotoOriginal), 0, 10).$extensao;
     $caminhoDaBig = "arquivos/acoes/fotos/big/{$nome_do_arquivo}";
     $caminhoDaFotoOriginal = "arquivos/acoes/fotos/original/{$nome_do_arquivo}";
     if ($imagewidth > 700) {
         $new_w = 700;
         $ratio = $imagewidth / $new_w;
         $new_h = ceil($imageheight / $ratio);
         $fim_largura = $new_w;
         $fim_altura = $new_h;
         if (!file_exists($caminhaDaBig)) {
             if ($img_type == "2") {
                 $src_img_original = @imagecreatefromjpeg($fotoOriginal);
                 $dst_img = @imagecreatetruecolor($new_w, $new_h);
                 imagecopyresized($dst_img, $src_img_original, 0, 0, 0, 0, $new_w, $new_h, imagesx($src_img_original), imagesy($src_img_original));
                 imagejpeg($dst_img, $caminhoDaBig);
             } else {
                 if ($img_type == "3") {
                     $src_img_original = @ImageCreateFrompng($fotoOriginal);
                     $dst_img = @imagecreatetruecolor($new_w, $new_h);
                     ImageCopyResized($dst_img, $src_img_original, 0, 0, 0, 0, $new_w, $new_h, ImageSX($src_img_original), ImageSY($src_img_original));
                     Imagepng($dst_img, $caminhoDaBig);
                 }
             }
         }
     } else {
         if (!file_exists($caminhoDaBig)) {
             copy($fotoOriginal, $caminhoDaBig);
             if ($img_type == "2") {
                 $src_img_original = @imagecreatefromjpeg($fotoOriginal);
             } else {
                 if ($img_type == "3") {
                     $src_img_original = @imagecreatefrompng($fotoOriginal);
                 }
             }
         }
     }
     $new_w = 100;
     $ratio = $imagewidth / $new_w;
     $new_h = round($imageheight / $ratio);
     $caminhoDaSmall = "arquivos/acoes/fotos/small/{$nome_do_arquivo}";
     if (!file_exists($caminhaDaBig)) {
         if ($img_type == "2") {
             $dst_img = @imagecreatetruecolor($new_w, $new_h);
             @imagecopyresized($dst_img, $src_img_original, 0, 0, 0, 0, $new_w, $new_h, imagesx($src_img_original), imagesy($src_img_original));
             @imagejpeg($dst_img, $caminhoDaSmall);
         } else {
             if ($img_type == "3") {
                 $dst_img = @imagecreatetruecolor($new_w, $new_h);
                 @imageCopyResized($dst_img, $src_img_original, 0, 0, 0, 0, $new_w, $new_h, ImageSX($src_img_original), imageSY($src_img_original));
                 @imagepng($dst_img, $caminhoDaSmall);
             }
         }
     }
     copy($fotoOriginal, $caminhoDaFotoOriginal);
     if (!(file_exists($fotoOriginal) && file_exists($caminhoDaSmall) && file_exists($caminhoDaBig))) {
         die("<center><br>Um erro ocorreu ao inserir a foto.<br>Por favor tente novamente.</center>");
     }
 }
コード例 #18
0
ファイル: Gd.php プロジェクト: edukondaluetg/mm
 public function cropAndResize($cropLeft, $cropTop, $cropWidth, $cropHeight, $resizeWidth, $resizeHeight)
 {
     $cropLeft = (int) $cropLeft;
     $cropTop = (int) $cropTop;
     $cropWidth = (int) $cropWidth;
     $cropHeight = (int) $cropHeight;
     $resizeWidth = (int) $resizeWidth;
     $resizeHeight = (int) $resizeHeight;
     $image = imageCreateTrueColor($resizeWidth, $resizeHeight);
     $this->_adjustTransparency($this->_object, $image);
     if ($this->_isTransparent($this->_object)) {
         imageCopyResized($image, $this->_object, 0, 0, $cropLeft, $cropTop, $resizeWidth, $resizeHeight, $cropWidth, $cropHeight);
     } else {
         imageCopyResampled($image, $this->_object, 0, 0, $cropLeft, $cropTop, $resizeWidth, $resizeHeight, $cropWidth, $cropHeight);
     }
     if ($this->_isResource($image)) {
         $this->_object = $image;
         return true;
     }
     throw new Exception("Failed to crop and resize object.");
 }
コード例 #19
0
ファイル: general.lib.php プロジェクト: jinzora/jinzora3
function createBlankImage($image, $font, $text, $color, $shadow, $drop, $maxwidth, $alignment, $valign, $padding = "5")
{
    global $web_root, $root_dir;
    // First we need to see if GD is installed or not...
    if (gd_version() == 0) {
        // Ok, no GD, let's write that to the log...
        writeLogData('error', 'Sorry, GD Libraries not found!');
        return false;
    }
    /* Now let's create our destination image with our new height/width */
    $src_img = imagecreatefromjpeg($image);
    if (gd_version() >= 2) {
        $dest_img = imageCreateTrueColor($maxwidth, $maxwidth);
    } else {
        $dest_img = imageCreate($maxwidth, $maxwidth);
    }
    // decode color arguments and allocate colors
    $color_args = explode(' ', $color);
    $color = imagecolorallocate($dest_img, $color_args[0], $color_args[1], $color_args[2]);
    $shadow_args = explode(' ', $shadow);
    $shadow = imagecolorallocate($dest_img, $shadow_args[0], $shadow_args[1], $shadow_args[2]);
    /* Let's get the width and height of the source image */
    $src_width = imagesx($src_img);
    $src_height = imagesy($src_img);
    /* Now let's copy the data from the old picture to the new one witht the new settings */
    if (gd_version() >= 2) {
        imageCopyResampled($dest_img, $src_img, 0, 0, 0, 0, $maxwidth, $maxwidth, $src_width, $src_height);
    } else {
        imageCopyResized($dest_img, $src_img, 0, 0, 0, 0, $maxwidth, $maxwidth, $src_width, $src_height);
    }
    /* Now let's clean up our temp image */
    imagedestroy($src_img);
    $fontwidth = ImageFontWidth($font);
    $fontheight = ImageFontHeight($font);
    $margin = floor($padding + $drop) / 2;
    // So that shadow is not off image on right align & bottom valign
    if ($maxwidth != NULL) {
        $maxcharsperline = floor(($maxwidth - $margin * 2) / $fontwidth);
        $text = wordwrap($text, $maxcharsperline, "\n", 1);
    }
    $lines = explode("\n", $text);
    switch ($valign) {
        case "center":
            $y = (imageSY($dest_img) - $fontheight * sizeof($lines)) / 2;
            break;
        case "bottom":
            $y = imageSY($dest_img) - ($fontheight * sizeof($lines) + $margin);
            break;
        default:
            $y = $margin;
            break;
    }
    switch ($alignment) {
        case "right":
            while (list($numl, $line) = each($lines)) {
                ImageString($dest_img, $font, imagesx($dest_img) - $fontwidth * strlen($line) - $margin + $drop, $y + $drop, $line, $shadow);
                ImageString($dest_img, $font, imagesx($dest_img) - $fontwidth * strlen($line) - $margin, $y, $line, $color);
                $y += $fontheight;
            }
            break;
        case "center":
            while (list($numl, $line) = each($lines)) {
                ImageString($dest_img, $font, floor((imagesx($dest_img) - $fontwidth * strlen($line)) / 2) + $drop, $y + $drop, $line, $shadow);
                ImageString($dest_img, $font, floor((imagesx($dest_img) - $fontwidth * strlen($line)) / 2), $y, $line, $color);
                $y += $fontheight;
            }
            break;
        default:
            while (list($numl, $line) = each($lines)) {
                ImageString($dest_img, $font, $margin + $drop, $y + $drop, $line, $shadow);
                ImageString($dest_img, $font, $margin, $y, $line, $color);
                $y += $fontheight;
            }
            break;
    }
    /* Now let's create our new image */
    $new_image = $web_root . $root_dir . "/temp/temp-image.jpg";
    @touch($new_image);
    // Now let's make sure that new image is writable
    if (is_writable($new_image)) {
        imagejpeg($dest_img, $new_image);
        /* Now let's clean up our temp image */
        imagedestroy($dest_img);
        return true;
    } else {
        echo "Sorry, I couldn't open the temporary image file for writing.<br>" . "looks like something is wrong with the permissions on your temp directory at:<br><br>" . $web_root . $root_dir . "/temp<br><br>" . "Sorry about that, but this is a fatal error!<br><br>" . "You could turn off auto art searching in settings.php by changing<br><br>" . '$search_album_art = "false";';
        exit;
        return false;
    }
}
<?php

/*Работа с изображениями.Часть 2 урок 2-12
 ***Функция imageCopyResized() - копирование и изменение размера части изображения(1-куда копируем ресурс изо создаваемое, 2-откуда копируем ресурс изо исходное, 3 - х-координата создаваемого изо, 4 - у-координата создаваемого изо, 5 - х-координата исходного изо, 6 - у-координата исходного изо, 7- ширина создаваемого изо, 8 - высота создаваемого изо, 9 - ширина исходного изо, 10 - высота исходного изо)
 */
$im = imageCreateTrueColor(400, 500);
$color = imageColorAllocate($im, 34, 34, 34);
imageFill($im, 100, 100, $color);
$color = imageColorAllocate($im, 100, 200, 3);
imageSetThickness($im, 5);
imageLine($im, 0, 0, imageSX($im), imageSY($im), $color);
$color = imageColorAllocate($im, 0, 40, 255);
imageFilledRectangle($im, 10, 10, 100, 100, $color);
$im2 = imageCreateTrueColor(100, 200);
imageCopyResized($im2, $im, 0, 0, 50, 50, imageSX($im2), imageSY($im2), 70, 70);
header("Content-type: image/png");
imagePng($im2);
imageDestroy($im);
imageDestroy($im2);
コード例 #21
0
 /** 
  * Creates a thumbnail picture (jpg/png) of a big image
  * 
  * @param	boolean 	$rescale
  * @return	string		thumbnail 
  */
 public function makeThumbnail($rescale = false)
 {
     list($width, $height, $this->imageType) = @getImageSize($this->sourceFile);
     // check image size
     if ($this->checkSize($width, $height, $rescale)) {
         return false;
     }
     // try to extract the embedded thumbnail first (faster)
     $thumbnail = false;
     if (!$rescale && $this->useEmbedded) {
         $thumbnail = $this->extractEmbeddedThumbnail();
     }
     if (!$thumbnail) {
         // calculate uncompressed filesize
         // and cancel to avoid a memory_limit error
         $memoryLimit = self::getMemoryLimit();
         if ($memoryLimit && $memoryLimit != -1) {
             $fileSize = $width * $height * ($this->imageType == 3 ? 4 : 3);
             if ($fileSize * 2.1 + memory_get_usage() > $memoryLimit) {
                 return false;
             }
         }
         // calculate new picture size
         $x = $y = 0;
         if ($this->quadratic) {
             $newWidth = $newHeight = $this->maxWidth;
             if ($this->appendSourceInfo) {
                 $newHeight -= self::$sourceInfoLineHeight * 2;
             }
             if ($width > $height) {
                 $x = ceil(($width - $height) / 2);
                 $width = $height;
             } else {
                 $y = ceil(($height - $width) / 2);
                 $height = $width;
             }
         } else {
             $maxHeight = $this->maxHeight;
             if ($this->appendSourceInfo) {
                 $maxHeight -= self::$sourceInfoLineHeight * 2;
             }
             if ($this->maxWidth / $width < $maxHeight / $height) {
                 $newWidth = $this->maxWidth;
                 $newHeight = round($height * ($newWidth / $width));
             } else {
                 $newHeight = $maxHeight;
                 $newWidth = round($width * ($newHeight / $height));
             }
         }
         // resize image
         $imageResource = false;
         // jpeg image
         if ($this->imageType == 2 && function_exists('imagecreatefromjpeg')) {
             $imageResource = @imageCreateFromJPEG($this->sourceFile);
         }
         // gif image
         if ($this->imageType == 1 && function_exists('imagecreatefromgif')) {
             $imageResource = @imageCreateFromGIF($this->sourceFile);
         }
         // png image
         if ($this->imageType == 3 && function_exists('imagecreatefrompng')) {
             $imageResource = @imageCreateFromPNG($this->sourceFile);
         }
         // could not create image
         if (!$imageResource) {
             return false;
         }
         // resize image
         if (function_exists('imageCreateTrueColor') && function_exists('imageCopyResampled')) {
             $imageNew = @imageCreateTrueColor($newWidth, $newHeight);
             imageAlphaBlending($imageNew, false);
             @imageCopyResampled($imageNew, $imageResource, 0, 0, $x, $y, $newWidth, $newHeight, $width, $height);
             imageSaveAlpha($imageNew, true);
         } else {
             if (function_exists('imageCreate') && function_exists('imageCopyResized')) {
                 $imageNew = @imageCreate($newWidth, $newHeight);
                 imageAlphaBlending($imageNew, false);
                 @imageCopyResized($imageNew, $imageResource, 0, 0, $x, $y, $newWidth, $newHeight, $width, $height);
                 imageSaveAlpha($imageNew, true);
             } else {
                 return false;
             }
         }
         // create thumbnail
         ob_start();
         if ($this->imageType == 1 && function_exists('imageGIF')) {
             @imageGIF($imageNew);
             $this->mimeType = 'image/gif';
         } else {
             if (($this->imageType == 1 || $this->imageType == 3) && function_exists('imagePNG')) {
                 @imagePNG($imageNew);
                 $this->mimeType = 'image/png';
             } else {
                 if (function_exists('imageJPEG')) {
                     @imageJPEG($imageNew, null, 90);
                     $this->mimeType = 'image/jpeg';
                 } else {
                     return false;
                 }
             }
         }
         @imageDestroy($imageNew);
         $thumbnail = ob_get_contents();
         ob_end_clean();
     }
     if ($thumbnail && $this->appendSourceInfo && !$rescale) {
         $thumbnail = $this->appendSourceInfo($thumbnail);
     }
     return $thumbnail;
 }
コード例 #22
0
ファイル: sysfunction.php プロジェクト: adjisukmana/eka
 public function upload_multiple_image($url, $name_image, $index)
 {
     $name = str_replace(" ", "_", "{$name_image}");
     $names = str_replace(",", "", "{$name}");
     $explode_string = explode(".", $name);
     $name_old_original = preg_replace("/^(.+?);.*\$/", "\\1", $names);
     $name_original = strtolower($name_old_original);
     $extension_unclear = $explode_string[count($explode_string) - 1];
     $file_type = preg_replace("/^(.+?);.*\$/", "\\1", $extension_unclear);
     $new_name_change = $name_original;
     $original_src = $url . strtolower(str_replace(' ', '_', $new_name_change));
     $thumbnail_src = $url . "thumbs/" . strtolower(str_replace(' ', '_', 'small-' . $new_name_change));
     if (move_uploaded_file($_FILES['userfile']['tmp_name'][$index], $original_src)) {
         chmod("{$original_src}", 0777);
     } else {
         $validate = "Gagal melakukan proses upload file.Hal ini biasanya disebabkan ukuran file yang terlalu besar atau koneksi jaringan anda sedang bermasalah";
         echo "<script type='text/javascript'> alert('" . $validate . "'); </script>";
         exit;
     }
     list($width, $height) = getimagesize($original_src);
     $x_height = $height >= 5000 ? 5000 : $height;
     $diff = $height / $x_height;
     $x_width = $width / $diff;
     $n_height = 220;
     $diff = $height / $n_height;
     $n_width = $width / $diff;
     if ($_FILES['userfile']['type'][$index] == "image/jpeg" || $_FILES['userfile']['type'][$index] == "image/png" || $_FILES['userfile']['type'][$index] == "image/gif") {
         $im = @ImageCreateFromJPEG($original_src) or $im = @ImageCreateFromPNG($original_src) or $im = @ImageCreateFromGIF($original_src) or $im = false;
         // If image is not JPEG, PNG, or GIF
         if (!$im) {
             $validate = "Gagal membuat thumbnail";
             echo "<script type='text/javascript'> alert('" . $validate . "'); </script>";
             exit;
         } else {
             $newimage2 = @imagecreatetruecolor($x_width, $x_height);
             @imageCopyResized($newimage2, $im, 0, 0, 0, 0, $x_width, $x_height, $width, $height);
             @ImageJpeg($newimage2, $original_src);
             chmod("{$original_src}", 0777);
             $newimage = @imagecreatetruecolor($n_width, $n_height);
             @imageCopyResized($newimage, $im, 0, 0, 0, 0, $n_width, $n_height, $width, $height);
             @ImageJpeg($newimage, $thumbnail_src);
             chmod($thumbnail_src, 0777);
         }
     }
 }
コード例 #23
0
ファイル: raxan.php プロジェクト: enriqueism/raxan
 /**
  * Resamples (convert/resize) an image file. You can specify a new width, height and type
  * @param string $file Image path and file name
  * @param int $w Width
  * @param int $h Height
  * @param string $type Supported image types: gif,png,jpg,bmp,xbmp,wbmp. Defaults to jpg
  * @return boolean
  */
 public static function imageResample($file, $w, $h, $type = null)
 {
     if (!function_exists('imagecreatefromstring')) {
         Raxan::log('Function imagecreatefromstring does not exists - The GD image processing library is required.', 'warn', 'Raxan::imageResample');
         return false;
     }
     $info = @getImageSize($file);
     if ($info) {
         // maintain aspect ratio
         if ($h == 0) {
             $h = $info[1] * ($w / $info[0]);
         }
         if ($w == 0) {
             $w = $info[0] * ($h / $info[1]);
         }
         if ($w == 0 && $h == 0) {
             $w = $info[0];
             $h = $info[1];
         }
         // resize/resample image
         $img = @imageCreateFromString(file_get_contents($file));
         if (!$img) {
             return false;
         }
         $newImg = function_exists('imagecreatetruecolor') ? imageCreateTrueColor($w, $h) : imageCreate($w, $h);
         if (function_exists('imagecopyresampled')) {
             imageCopyResampled($newImg, $img, 0, 0, 0, 0, $w, $h, $info[0], $info[1]);
         } else {
             imageCopyResized($newImg, $img, 0, 0, 0, 0, $w, $h, $info[0], $info[1]);
         }
         imagedestroy($img);
         $type = !$type ? $info[2] : strtolower(trim($type));
         if ($type == 1 || $type == 'gif') {
             $f = 'imagegif';
         } else {
             if ($type == 3 || $type == 'png') {
                 $f = 'imagepng';
             } else {
                 if ($type == 6 || $type == 16 || $type == 'bmp' || $type == 'xbmp') {
                     $f = 'imagexbm';
                 } else {
                     if ($type == 15 || $type == 'wbmp') {
                         $f = 'image2wbmp';
                     } else {
                         $f = 'imagejpeg';
                     }
                 }
             }
         }
         if (function_exists($f)) {
             $f($newImg, $file);
         }
         imagedestroy($newImg);
         return true;
     }
     return false;
 }
コード例 #24
0
ファイル: Image2.php プロジェクト: nachoweb/mbf-dev
 function resizeCropped($width, $height)
 {
     if (!$this->image) {
         return FALSE;
     }
     $oldWidth = imageSX($this->image);
     $oldHeight = imageSY($this->image);
     $ratioW = $oldWidth / $width;
     $ratioH = $oldHeight / $height;
     if ($ratioH > $ratioW) {
         // some parts from the height will have to be cut off
         $newWidth = $oldWidth;
         $newHeight = $height * $ratioW;
         $srcX = 0;
         $srcY = +($oldHeight - $newHeight) / 2;
     } else {
         // some parts from the width will have to be cut off
         $newWidth = $width * $ratioH;
         $newHeight = $oldHeight;
         $srcX = +($oldWidth - $newWidth) / 2;
         $srcY = 0;
     }
     $imageNew = ImageCreateTrueColor($newWidth, $newHeight);
     imageCopyResized($imageNew, $this->image, 0, 0, $srcX, $srcY, $oldWidth, $oldHeight, $oldWidth, $oldHeight);
     imageDestroy($this->image);
     $this->image = $imageNew;
     // Now we are actually going to resample the image to the correct size
     $oldWidth = $newWidth;
     $oldHeight = $newHeight;
     $newWidth = $width;
     $newHeight = $height;
     $imageNew = ImageCreateTrueColor($newWidth, $newHeight);
     imageCopyResampled($imageNew, $this->image, 0, 0, 0, 0, $newWidth, $newHeight, $oldWidth, $oldHeight);
     imageDestroy($this->image);
     $this->image = $imageNew;
     return TRUE;
 }
コード例 #25
0
ファイル: mxGdCanvas.php プロジェクト: maojinhui/mxgraph
 /**
  * Function: drawImage
  *
  * Draws a given image.
  */
 function drawImage($x, $y, $w, $h, $image, $aspect = true, $flipH = false, $flipV = false)
 {
     $img = $this->loadImage($image);
     if ($img != null) {
         $iw = imagesx($img);
         $ih = imagesy($img);
         // Horizontal and vertical image flipping
         if ($flipH || $flipV) {
             $img = mxUtils::flipImage($img, $flipH, $flipV);
         }
         // Preserved aspect ratio
         if ($aspect) {
             $s = min($w / $iw, $h / $ih);
             $x0 = ($w - $iw * $s) / 2;
             $y0 = ($h - $ih * $s) / 2;
             imageCopyResized($this->image, $img, $x0 + $x, $y0 + $y, 0, 0, $iw * $s, $ih * $s, $iw, $ih);
         } else {
             imageCopyResized($this->image, $img, $x, $y, 0, 0, $w, $h, $iw, $ih);
         }
     }
 }
コード例 #26
0
ファイル: lib_ahash.php プロジェクト: ericpony/Pixmicat
 public static function hashImage($src)
 {
     if (!$src) {
         return false;
     }
     /*缩小圖片尺寸*/
     $delta = 8 * self::$rate;
     $img = imageCreateTrueColor($delta, $delta);
     imageCopyResized($img, $src, 0, 0, 0, 0, $delta, $delta, imagesX($src), imagesY($src));
     /*計算圖片灰階值*/
     $grayArray = array();
     for ($y = 0; $y < $delta; $y++) {
         for ($x = 0; $x < $delta; $x++) {
             $rgb = imagecolorat($img, $x, $y);
             $col = imagecolorsforindex($img, $rgb);
             $gray = intval(($col['red'] + $col['green'] + $col['blue']) / 3) & 0xff;
             $grayArray[] = $gray;
         }
     }
     imagedestroy($img);
     /*計算所有像素的灰階平均值*/
     $average = array_sum($grayArray) / count($grayArray);
     /*計算 hash 值*/
     $hashStr = '';
     foreach ($grayArray as $gray) {
         $hashStr .= $gray >= $average ? '1' : '0';
     }
     return $hashStr;
 }
コード例 #27
0
ファイル: class.cl.images.php プロジェクト: renekliment/CLE
 /**
  * This function resizes given image, if it has bigger dimensions, than we need and saves it (also makes chmod 0777 on the file) ...
  * It uses GD or ImageMagick, setting is available to change in CL's config file.
  *
  * @param string $inputFileName the input file to work with
  * @param string $outputFileName the file to write into the final (resized) image
  * @param integer $maxNewWidth maximal width of image
  * @param integer $maxNewHeight maximal height of image
  * @return bool TRUE, if everything was successful (resize and chmod), else FALSE
  */
 function resize($inputFileName, $outputFileName, $maxNewWidth, $maxNewHeight)
 {
     $imageInfo = getimagesize($inputFileName);
     $fileType = $imageInfo['mime'];
     $extension = strtolower(str_replace('.', '', substr($outputFileName, -4)));
     $originalWidth = $imageInfo[0];
     $originalHeight = $imageInfo[1];
     if ($originalWidth > $maxNewWidth or $originalHeight > $maxNewHeight) {
         $newWidth = $maxNewWidth;
         $newHeight = $originalHeight / ($originalWidth / $maxNewWidth);
         if ($newHeight > $maxNewHeight) {
             $newHeight = $maxNewHeight;
             $newWidth = $originalWidth / ($originalHeight / $maxNewHeight);
         }
         $newWidth = ceil($newWidth);
         $newHeight = ceil($newHeight);
     } else {
         $newWidth = $originalWidth;
         $newHeight = $originalHeight;
     }
     $ok = FALSE;
     if (CL::getConf('CL_Images/engine') == 'imagick-cli') {
         exec("convert -thumbnail " . $newWidth . "x" . $newHeight . " " . $inputFileName . " " . $outputFileName);
         $ok = TRUE;
     } elseif (CL::getConf('CL_Images/engine') == 'imagick-php') {
         $image = new Imagick($inputFileName);
         $image->thumbnailImage($newWidth, $newHeight);
         $ok = (bool) $image->writeImage($outputFileName);
         $image->clear();
         $image->destroy();
     } else {
         $out = imageCreateTrueColor($newWidth, $newHeight);
         switch (strtolower($fileType)) {
             case 'image/jpeg':
                 $source = imageCreateFromJpeg($inputFileName);
                 break;
             case 'image/png':
                 $source = imageCreateFromPng($inputFileName);
                 break;
             case 'image/gif':
                 $source = imageCreateFromGif($inputFileName);
                 break;
             default:
                 break;
         }
         imageCopyResized($out, $source, 0, 0, 0, 0, $newWidth, $newHeight, $originalWidth, $originalHeight);
         switch (strtolower($extension)) {
             case 'jpg':
             case 'jpeg':
                 if (imageJpeg($out, $outputFileName)) {
                     $ok = TRUE;
                 }
                 break;
             case 'png':
                 if (imagePng($out, $outputFileName)) {
                     $ok = TRUE;
                 }
                 break;
             case 'gif':
                 if (imageGif($out, $outputFileName)) {
                     $ok = TRUE;
                 }
                 break;
             default:
                 break;
         }
         imageDestroy($out);
         imageDestroy($source);
     }
     if ($ok and chmod($outputFileName, 0777)) {
         return TRUE;
     } else {
         return FALSE;
     }
 }
コード例 #28
0
ファイル: ImageResize.php プロジェクト: mbassan/backstage2
 function _build()
 {
     // scale
     if ($this->_dest_height == -1 || $this->_dest_width == -1) {
         if ($this->_dest_height != -1) {
             $rat = $this->_dest_height / $this->_image_height;
         } else {
             $rat = $this->_dest_width / $this->_image_width;
         }
         $dest_width = ceil($rat * $this->_image_width);
         $dest_height = ceil($rat * $this->_image_height);
         $this->_dest_image = imageCreateTruecolor($dest_width, $dest_height);
         imageCopyResampled($this->_dest_image, $this->_image, 0, 0, 0, 0, $dest_width, $dest_height, $this->_image_width, $this->_image_height);
         return;
     } else {
         $this->_dest_image = imageCreateTruecolor($this->_dest_width, $this->_dest_height);
         $bg_color = ImageColorAllocate($this->_dest_image, 255, 255, 255);
         //imageFill($this->_dest_image,0,0,$bg_color);
         //was causing exhausted memory problems - andy
         imagefilledrectangle($this->_dest_image, 0, 0, $this->_dest_width, $this->_dest_height, $bg_color);
         $imagemaxratio = $this->_dest_width / $this->_dest_height;
         $imageratio = $this->_image_width / $this->_image_height;
         // basically eliminate the white space by swapping the ratios
         if ($this->_auto_crop) {
             $tmp = $imagemaxratio;
             $imagemaxratio = $imageratio;
             $imageratio = $tmp;
             unset($tmp);
         }
         if ($this->_keep_if_smaller && $this->_image_width <= $this->_dest_width && $this->_image_height <= $this->_dest_height) {
             $dest_width = $this->_image_width;
             $dest_height = $this->_image_height;
         } else {
             if ($imageratio > $imagemaxratio) {
                 $dest_width = $this->_dest_width;
                 $dest_height = ceil($this->_dest_width / $this->_image_width * $this->_image_height);
             } else {
                 if ($imageratio < $imagemaxratio) {
                     $dest_height = $this->_dest_height;
                     $dest_width = ceil($this->_dest_height / $this->_image_height * $this->_image_width);
                 } else {
                     $dest_width = $this->_dest_width;
                     $dest_height = $this->_dest_height;
                 }
             }
         }
     }
     // center
     if ($this->_auto_center) {
         $dest_x = ($this->_dest_width - $dest_width) / 2;
         $dest_y = ($this->_dest_height - $dest_height) / 2;
     } else {
         $dest_x = 0;
         $dest_y = 0;
     }
     //var_dump($dest_width);
     //var_dump($dest_height);
     // resize
     if ($this->_high_quality) {
         imageCopyResampled($this->_dest_image, $this->_image, $dest_x, $dest_y, 0, 0, $dest_width, $dest_height, $this->_image_width, $this->_image_height);
     } else {
         imageCopyResized($this->_dest_image, $this->_image, $dest_x, $dest_y, 0, 0, $dest_width, $dest_height, $this->_image_width, $this->_image_height);
     }
 }
コード例 #29
0
ファイル: GdMediaAdapter.php プロジェクト: razzman/media
 function cropAndResize($Media, $cropLeft, $cropTop, $cropWidth, $cropHeight, $resizeWidth, $resizeHeight)
 {
     $cropLeft = (int) $cropLeft;
     $cropTop = (int) $cropTop;
     $cropWidth = (int) $cropWidth;
     $cropHeight = (int) $cropHeight;
     $resizeWidth = (int) $resizeWidth;
     $resizeHeight = (int) $resizeHeight;
     $Image = imageCreateTrueColor($resizeWidth, $resizeHeight);
     $this->_adjustTransparency($Media->resources['gd'], $Image);
     if ($this->_isTransparent($Media->resources['gd'])) {
         imageCopyResized($Image, $Media->resources['gd'], 0, 0, $cropLeft, $cropTop, $resizeWidth, $resizeHeight, $cropWidth, $cropHeight);
     } else {
         imageCopyResampled($Image, $Media->resources['gd'], 0, 0, $cropLeft, $cropTop, $resizeWidth, $resizeHeight, $cropWidth, $cropHeight);
     }
     if ($this->_isResource($Image)) {
         $Media->resources['gd'] = $Image;
         return true;
     }
     return false;
 }
コード例 #30
0
 /**
  * Function: drawImage
  *
  * Draws a given image.
  */
 function drawImage($x, $y, $w, $h, $image)
 {
     $img = $this->loadImage($image);
     if ($img != null) {
         imageCopyResized($this->image, $img, $x, $y, 0, 0, $w, $h, imagesx($img), imagesy($img));
     }
 }