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

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

Jul 13, 2016 am 10:45 AM
php アップロード そして 追加 できる 写真 透かし 生成する 親切

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 図形上に転送されるコードは、ウォーターインを追加しながら略図を生成することができます。 このセクション図形上に転送されるコードは、上に転送される図形にウォーターインを追加し、小さな図形を生成し、同時に文字ウォーターインを生成することもできます。
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

AI Hentai Generator

AI Hentai Generator

AIヘンタイを無料で生成します。

ホットツール

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

SublimeText3 中国語版

SublimeText3 中国語版

中国語版、とても使いやすい

ゼンドスタジオ 13.0.1

ゼンドスタジオ 13.0.1

強力な PHP 統合開発環境

ドリームウィーバー CS6

ドリームウィーバー CS6

ビジュアル Web 開発ツール

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)

Ubuntu および Debian 用の PHP 8.4 インストールおよびアップグレード ガイド Ubuntu および Debian 用の PHP 8.4 インストールおよびアップグレード ガイド Dec 24, 2024 pm 04:42 PM

PHP 8.4 では、いくつかの新機能、セキュリティの改善、パフォーマンスの改善が行われ、かなりの量の機能の非推奨と削除が行われています。 このガイドでは、Ubuntu、Debian、またはその派生版に PHP 8.4 をインストールする方法、または PHP 8.4 にアップグレードする方法について説明します。

CakePHP の日付と時刻 CakePHP の日付と時刻 Sep 10, 2024 pm 05:27 PM

Cakephp4 で日付と時刻を操作するには、利用可能な FrozenTime クラスを利用します。

CakePHP ファイルのアップロード CakePHP ファイルのアップロード Sep 10, 2024 pm 05:27 PM

ファイルのアップロードを行うには、フォーム ヘルパーを使用します。ここではファイルアップロードの例を示します。

CakePHP について話し合う CakePHP について話し合う Sep 10, 2024 pm 05:28 PM

CakePHP は、PHP 用のオープンソース フレームワークです。これは、アプリケーションの開発、展開、保守をより簡単にすることを目的としています。 CakePHP は、強力かつ理解しやすい MVC のようなアーキテクチャに基づいています。モデル、ビュー、コントローラー

CakePHP バリデータの作成 CakePHP バリデータの作成 Sep 10, 2024 pm 05:26 PM

Validator は、コントローラーに次の 2 行を追加することで作成できます。

CakePHP データベースの操作 CakePHP データベースの操作 Sep 10, 2024 pm 05:25 PM

CakePHP でデータベースを操作するのは非常に簡単です。この章では、CRUD (作成、読み取り、更新、削除) 操作について理解します。

PHP 開発用に Visual Studio Code (VS Code) をセットアップする方法 PHP 開発用に Visual Studio Code (VS Code) をセットアップする方法 Dec 20, 2024 am 11:31 AM

Visual Studio Code (VS Code とも呼ばれる) は、すべての主要なオペレーティング システムで利用できる無料のソース コード エディター (統合開発環境 (IDE)) です。 多くのプログラミング言語の拡張機能の大規模なコレクションを備えた VS Code は、

CakePHP のロギング CakePHP のロギング Sep 10, 2024 pm 05:26 PM

CakePHP へのログインは非常に簡単な作業です。使用する関数は 1 つだけです。 cronjob などのバックグラウンド プロセスのエラー、例外、ユーザー アクティビティ、ユーザーが実行したアクションをログに記録できます。 CakePHP でのデータのログ記録は簡単です。 log()関数が提供されています

See all articles