PHP 画像アップロード クラスはサムネイルの生成と透かしの追加を同時に行うことができます_PHP チュートリアル

WBOY
リリース: 2016-07-13 10:45:13
オリジナル
1122 人が閲覧しました

php画像アップロードクラスはサムネイルの生成と透かしの追加を同時に行うことができます この画像アップロード コードは、アップロードされた画像に透かしを追加したり、小さな画像を生成したり、テキストの透かしを生成したりできます。

PHP チュートリアルの画像アップロード クラスでは、サムネイルの生成と透かしの追加を同時に行うことができます
この画像アップロード コードは、アップロードされた画像に透かしを追加したり、小さな画像を生成したり、テキストの透かしを生成したりできます。

クラスアップ画像 {
var $annexfolder = "upload";//添付ファイルの保存ポイント、デフォルトは: annex
var $smallfolder = "small";//サムネイルの保存パス、注意: $annexfolder の下のサブディレクトリに配置する必要があり、デフォルトは smallimg
var $markfolder = "mark";//ウォーターマーク画像の保管場所
var $upfiletype = "jpg gif png";//アップロードの種類、デフォルトは: jpg gif png rar zip
var $upfilemax = 1024; //アップロード サイズ制限、単位は「kb」、デフォルトは 1024kb
var $fonttype;//フォント
var $maxwidth = 500 //画像の最大幅
; var $maxheight = 600 //画像の最大高さ
; 関数 upimages($annexfolder,$smallfolder,$includefolder) {
                                                                                                                                                                                                                                                  $this->smallfolder = $smallfolder;
$this->fonttype = $includefolder."/04b_08__.ttf";
}
関数アップロード($inputname) {
$imagename = time();// 現在の時間を画像名として設定します
If(@empty($_files[$inputname]["name"])) die("画像情報がアップロードされていません。ご確認ください");
$name =explode(".",$_files[$inputname]["name"]);//アップロードする前にファイルを「.」で区切ってファイルタイプを取得します
$ Imgcount = Count ($ Name) // インターセプト数を取得します
; $imgtype = $name[$imgcount-1];// ファイルの種類を取得します
If(strpos($this->upfiletype,$imgtype) === false) die(error("アップロード ファイル タイプは ".$this->upfiletype のみをサポートします。" は ".$imgtype" をサポートしません));
$ photo = $ imagename。 "。"。$ imgtype; //ファイル名データベースチュートリアルに書き込む $uploadfile = $this->annexfolder."/".$photo;//アップロードされたファイルの名前
$upfileok = move_uploaded_file($_files[$inputname]["tmp_name"],$uploadfile);
If($upfileok) {
$imgsize = $_files[$inputname]["size"];
$ksize =round($imgsize/1024);
If($ksize > ($this->upfilemax*1024)) {
                                                                                                                                                          die(error("アップロードされたファイルが ".$this->upfilemax."kb" を超えています));
                                                                                                                    } else {
die(エラー( "画像のアップロードに失敗した場合、アップロードされたファイルが$ upfilemax kbまたはアップロードタイムアウトを超えないことを確認してください");
}
$photo を返す;
}
関数 getinfo($photo) {
$photo = $this->別館フォルダー."/".$photo;
$imageinfo = getimagesize($photo);
$imginfo["width"] = $imageinfo[0];
$imginfo["高さ"] = $imageinfo[1];
$imginfo["type"] = $imageinfo[2];
$imginfo["名前"] = ベース名($photo);
$imginfo;
を返す }
関数 smallimg($photo,$width=128,$height=128) {
$imginfo = $this->getinfo($photo);
$photo = $this->annexfolder."/".$photo;//画像ソースを取得します
$newname = substr($imginfo["name"],0,strrpos($imginfo["name"], "."))."_thumb.jpg";//新しい画像名
If($imginfo["type"] == 1) {
$img = imagecreatefromgif($photo);
} elseif($imginfo["type"] == 2) {
$img = imagecreatefromjpeg($photo);
} elseif($imginfo["type"] == 3) {
$img = imagecreatefrompng($photo);
} else {
$img = "";
}
If(empty($img)) は false を返します;
$width = ($width > $imginfo["width"]) $imginfo["width"] : $width; $height = ($height > $imginfo["height"]) $imginfo["height"] : $height; $srcw = $imginfo["width"]; $srch = $imginfo["高さ"]; If ($srcw * $width > $srch * $height) {
$height =round($srch * $width / $srcw);
} else {
                        $width =round($srcw * $height / $srch);
                }
                if (function_exists("imagecreatetruecolor")) {
                        $newimg = imagecreatetruecolor($width, $height);
                        imagecopyresampled($newimg, $img, 0, 0, 0, 0, $width, $height, $imginfo["width"], $imginfo["height"]);
                } その他 {
                        $newimg = imagecreate($width, $height);
                        imagecopyresize($newimg, $img, 0, 0, 0, 0, $width, $height, $imginfo["width"], $imginfo["height"]);
                }
                if ($this->tofile) {
                        if (file_exists($this->annexfolder."/".$this->smallfolder."/".$newname)) @unlink($this->annexfolder."/".$this->smallfolder) ."/".$新しい名前);
                        imagejpeg($newimg,$this->annexfolder."/".$this->smallfolder."/".$newname);
                        return $this->annexfolder."/".$this->smallfolder."/".$newname;
                } その他 {
                        imagejpeg($newimg);
                }
                imagedestroy($newimg);
                imagedestroy($img);
                $newname を返します;
        }
        関数ウォーターマーク($photo,$text) {
                $imginfo = $this->getinfo($photo);
                $photo = $this->別館フォルダー."/".$photo;
                $newname = substr($imginfo["name"], 0, strrpos($imginfo["name"], ".")) 。 "_mark.jpg";
                スイッチ ($imginfo["type"]) {
                        ケース1:
                                $img = imagecreatefromgif($photo);
                        休憩;
                        ケース 2:
                                $img = imagecreatefromjpeg($photo);
                        休憩;
                        ケース 3:
                                $img = imagecreatefrompng($photo);
                        休憩;
                        デフォルト:
                                false を返します;
                }
                if (empty($img)) return false;
                $width = ($this->maxwidth>$imginfo["width"]) ? $imginfo["width"] : $this->maxwidth;
                $height = ($this->maxheight>$imginfo["height"]) ? $imginfo["高さ"] : $this->maxheight;
                $srcw = $imginfo["幅"];
                $srch = $imginfo["身長"];
                if ($srcw * $width > $srch * $height) {
                        $height =round($srch * $width / $srcw);
                } その他 {
                        $width =round($srcw * $height / $srch);
                }
                if (function_exists("imagecreatetruecolor")) {
                        $newimg = imagecreatetruecolor($width, $height);
                        imagecopyresampled($newimg, $img, 0, 0, 0, 0, $width, $height, $imginfo["width"], $imginfo["height"]);
                } その他 {
                        $newimg = imagecreate($width, $height);
                        imagecopyresize($newimg, $img, 0, 0, 0, 0, $width, $height, $imginfo["width"], $imginfo["height"]);
                }
               
                $white = imagecolorallocate($newimg, 255, 255, 255);
                $black = imagecolorallocate($newimg, 0, 0, 0);
                $alpha = imagecolorallocatealpha($newimg, 230, 230, 230, 40);
                imagefilledrectangle($newimg, 0, $height-26, $width, $height, $alpha);
                imagefilledrectangle($newimg, 13, $height-20, 15, $height-7, $black);
                imagettftext($newimg, 4.9, 0, 20, $height-14, $black, $this->fonttype, $text[0]);
                imagettftext($newimg, 4.9, 0, 20, $height-6, $black, $this->fonttype, $text[1]);
                if($this->tofile) {
                        if (file_exists($this->annexfolder."/".$this->markfolder."/".$newname)) @unlink($this->annexfolder."/".$this->markfolder) ."/".$新しい名前);
                        imagejpeg($newimg,$this->annexfolder."/".$this->markfolder."/".$newname);
                        return $this->annexfolder."/".$this->markfolder."/".$newname;
                } その他 {
                        imagejpeg($newimg);
                }
                imagedestroy($newimg);
                imagedestroy($img);
                $newname を返します;
        }
}

www.bkjia.comtru​​ehttp://www.bkjia.com/PHPjc/633040.html技術記事 php 図形上に転送されるコードは、ウォーターインを追加しながら略図を生成することができます。 このセクション図形上に転送されるコードは、上に転送される図形にウォーターインを追加し、小さな図形を生成し、同時に文字ウォーターインを生成することもできます。
ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
最新の問題
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!