検索
ホームページphp教程php手册PHPの画像関数の大きな例(オリジナルではありません)

PHPの画像関数の大きな例(オリジナルではありません)

Jun 13, 2016 pm 12:23 PM
existsfunctionphp関数オリジナル画像大きい方法方法はいいいえ

次のメソッドはメソッドです:
if(!function_exists('imagecreate')) {
die('このサーバーは GD モジュールをサポートしていません')
}
if サポートされていない場合、どのように設定すればよいでしょうか? gd モジュールの dll ファイルをダウンロードし、php.ini を変更して、サーバーを再起動します。
以降、PHP 描画と呼ばれます。
PS を使用する場合は、次の手順を完了する必要があります。
1: 基本的な PS オブジェクト ($image であるとします) を作成し、背景 (デフォルトは黒) を塗りつぶします。 PS の操作は、この背景画像に基づいています。
3: 画像を出力します。
まず、オブジェクトを破棄します。これらの関数は PHP にあります。マニュアルには詳細な説明があり、ここで一般的に引用されています。
resource imagecreate (int x_size, int y_size)
imagecreate() はイメージ識別子を返します。サイズ x_size と y_size の空白の画像を表します。
この関数は基本的に imagetruecolor($width,$height) と同じです。
---------------------------- ----- ------------------------
int imagecolorallocate (リソース画像、int red、int green、int blue)
imagecolorallocate() 指定された RGB コンポーネントで構成される色を表す識別子を返します。 image パラメータは、imagecreatetruecolor() 関数の戻り値です。赤、緑、青は、それぞれ目的の色の赤、緑、青の成分です。これらのパラメータは、0 ~ 255 の整数、または 16 進数の 0x00 ~ 0xFF です。 image で表される画像で使用される各色を作成するには、imagecolorallocate() を呼び出す必要があります。
----------------------------------------------- --- ----------
bool imagefill ( resource image, int x, int y, int color )
imagefill() イメージimage(左上)の座標x,y画像の隅が 0, 0 ) は、カラー color で領域を塗りつぶすために使用されます (つまり、x、y 点と同じ色の点および隣接する点が塗りつぶされます)。
----------------------------------------------- --- ----------
bool imageline ( resource image, int x1, int y1, int x2, int y2, int color )
imageline() は、イメージ image のカラー color を使用します。座標 x1 , y1 ~ x2, y2 (画像の左上隅が 0, 0) で線分を描きます。
----------------------------------------------- --- ----------
bool imagestring ( resource image, int font, int x, int y, string s, int col )
imagestring() は、col color を使用して文字列 s を描画しますto image 表現されるイメージの x、y 座標 (これは文字列の左上隅の座標であり、イメージ全体の左上隅は 0, 0 です)。フォントが 1、2、3、4、または 5 の場合は、内蔵フォントが使用されます。
----------------------------------------------- --- ----------
array imagettftext ( resource image, float size, float angle, int x, int y, int color, string fontfile, string text )
この関数は詳細です重要でパラメータは小さいため、ここではリストしません。これは主に画像にテキストを書き込みます。これは上記の関数に似ていますが、前者よりも強力です。 -------------------------------------------------------- -
bool imagefilltoborder ( resource image, int x, int y, int border, int color )
imagefilltoborder() x, y (画像の左上隅が 0, 0) 点から開始して、実行します。色の境界線に達するまで、領域を色で塗りつぶします。 [注: 境界線内のすべての色が塗りつぶされます。指定した境界線の色がポイントと同じ場合、塗りつぶしはありません。画像に境界線の色が存在しない場合は、画像全体が塗りつぶされます。 】
---------------------------------------------- --- --
bool imagefilledellipse ( resource image, int cx, int cy, int w, int h, int color )
imagefilledellipse() image で表される画像では、cx, cy (左上) を使用します。画像の隅が 0, 0) 中心に楕円を描きます。 w と h はそれぞれ楕円の幅と高さを指定します。楕円は色で塗りつぶされます。成功した場合は TRUE、失敗した場合は FALSE を返します。
=========================================== === ==
出力画像データ: imagepng($image[,$filename])
========================= === ==========================
例 1: 青色の背景と交差した白い線を持つグラフィックを出力します
$width=35;
$height=35;
//オブジェクトを作成
$image=imagecreate($width,$height);
//色を抽出します$color_white= imagecolorallocate($image,255,255,255);//白
$color_blue=imagecolorallocate($image,0,0,108);//青
imagefill($image,0,0,$color_blue); 🎜> //描画
//線幅
imagesetthickness($image,3);
imageline($image,0,0,$width,$height,$color_white); $ image,$width,0,0,$height,$color_white);
// オブジェクトをヘッダーに送信します
header('content-type:image/png'); image);
/*
// オブジェクトをファイルに送信します
$filename="ex1.png";
imagepng($image,$filename); /Destroy object
imagedestroy($image);
?>
出力イメージ:
オンライン デモ: http://www.phzzy.org/temp/5do8/ex1.php
例 2: 陰陽図
$width=400;
$image=imagetruecolor($width,$height);色の抽出
$color_black=imagecolorallocate($image,0,2,0);//
$color_white=imagecolorallocate($image,255,255,255);// ホワイト
$color_blue=imagecolorallocate($image, 0,0,108); //青
$color_red=imagecolorallocate($image,151,0,4);//赤
$color_my=imagecolorallocate($image,192,192,255);//背景
$ color_temp=imagecolorallocate( $image,199,199,199);//Background
//Image
imagefill($image,0,0,$color_white);//最初の円は大きな円です
imagefilledarc ($image, $width/2,$height/2,$height,$height,0,360,$color_blue,IMG_ARC_PIE);
//2 つの小さな円
imagefilledellipse ($image,$width/2, $height/4 ,$height/2,$height/2,$color_red);
imagefilledellipse ($image,$width/2,$height/4 * 3,$height/2,$height/2,$) color_blue);
/*imagefilledellipse -- 楕円を描いて塗りつぶします*/
imagefilledarc ($image,$width/2,$height/2,$height,$height,-90,90,$color_red ,IMG_ARC_PIE);
imagefilledellipse ($image,$width/2,$height/4 * 3,$height/2,$height/2,$color_blue);
// オブジェクトをヘッダーに送信します
header('content-type:image/png');
imagepng($image);
/*
//オブジェクトをファイルに送信します
$filename="ex1.png";
imagepng($image ,$filename);
*/
// オブジェクトを破棄します
imagedestroy($image);
デモ:
http: //www.phzzy.org/temp/5do8/ex2.php
例 3: 3D 画像 --cool
$width=400;
$height=400; 🎜>$image = imagecreatetruecolor($ width, $height);
$white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
$gray = imagecolorallocate($image, 0xC0, 0xC0, 0xC0);
$darkgray = imagecolorallocate($image, 0x90, 0x90, 0x90);
$navy = imagecolorallocate($image, 0x00, 0x00, 0x80);
$darknavy = imagecolorallocate($image, 0x00, 0x00) , 0x50);
$ red = imagecolorallocate($image, 0xFF, 0x00, 0x00);
$darkred = imagecolorallocate($image, 0x00, 0x00); 0,$white);
// 3D 効果を作成します
for ($i = $height /2 20; $i > $height /2; $i--) {
imagefilledarc($)画像、$width/2、$ i、$width/2、$height /2、0、45、$darknavy、IMG_ARC_PIE);
imagefilledarc($image, $width/2, $i, $width/2); , $height /2, 45, 75, $darkgray, IMG_ARC_PIE);
imagefilledarc($image, $width/2, $i, $width/2, $height /2, 75, 360, $darkred, IMG_ARC_PIE );
}
imagefilledarc($image, $width/2, $height /2, $width/2, $height /2, 0, 45, $navy, IMG_ARC_PIE);
imagefilledarc($image, $width/2) , $height /2, $width/2, $height /2, 45, 75 , $gray, IMG_ARC_PIE);
imagefilledarc($image, $width/2, $height /2, $width/2, $高さ /2, 75, 360 , $red, IMG_ARC_PIE);
// フラッシュイメージ
header('Content-type: image/png');
imagepng($image); ($image);
/*
// オブジェクトをファイルに送信します
$filename="ex1.png";
imagepng($image,$filename); >?>
出力:
デモ: http://www.phzzy.org/temp/5do8/ex3.php

例 4: 単純な検証コード
PHP 作成の検証コードは非常に簡単で、簡単なアイデアは次のとおりです:
ランダムなシードを生成し、ランダムな文字を抽出し、グラフィックスに接続して出力します。色覚異常を防ぐために、色をランダムに抽出したり、色をカスタマイズしたりできます。
session_start();
$width=65;
$sourcestrings="0123456789aqwertyuiopasdfghjklzxcvbnm"; image=image create ($width,$height);
$colorarrs=array(
imagecolorallocate($image,255,255,255),//white
imagecolorallocate($image,0 ,0 , 0)// black
);
unset($sessionval);
imagesetthickness($image,3)
//文字列の数をランダムに取得します
$strsize=rand(3,5);
imagefill ($image,0,0,$colorarrs[0]);
//文字列を 1 つずつ画像に書き込みます
for($i=0;$i$i_temp=rand(1,62);
$sessionval .=$sourcestrings[$i_temp]
$fontcolor=imagecolorallocate($image,rand(0,255),rand(0,255),rand (0,255) );
$y_i = $height/2 $font_size /3 ;
imagechar($image,5, 1 $i * $width /$strsize,5,$sourcestrings[$i_temp],$ fontcolor);
}
//セッションに書き込み、後で
unset($_SESSION['cjjer']) で検証します。
$_SESSION['cjjer'] = $sessionval; //ノイズを追加
for($i=0;$i{ $i_x=rand(0,$width)
$i_y=rand; (0 ,$height);
$pixelcolor=imagecolorallocate($image,rand(0,255),rand(0,255),rand(0,255));
imagesetpixel($image,$i_x,$i_y,$pixelcolor) );
}
header('content-type:image/png');
imagedestroy($image);
生成スタイル デモ:
オンライン デモ: http://www.phzzy.org/temp/5do8/ex4_login.php
明らかな問題は、生成された画像が十分に明るくないため、多くのユーザーにははっきりと見えないことです。これをやってみましょう。いくつかの明るい色を自分で設定して出力し、colorarrs 配列を拡張します。
$colorarrs=array(
imagecolorallocate($image,255,255,255),
imagecolorallocate($image,0) ,0 ,0)、
imagecolorallocate($image,0,70,0)、
imagecolorallocate($image,92,0,12)、
imagecolorallocate($image,0,0,128)、
imagecolorallocate($image,233,10,216)
);
次に、23 行目を (17 行目) に変更します。
$fontcolor=$colorarrs[rand(1,count($colorarrs)-1) ] ;
出力:
オンラインデモ: http://www.phzzy.org/temp/5do8/ex5_login.php
例 5: より大きくてクールな検証コード
PS イメージはまだ比較的小さいこともありますが、何らかの理由で (個人用サイトはクールのため、私だけ、商用サイトはスタイルとユーザーを惹きつけるため、Google だけ、詳細は後ほど)、確認コードは数十ピクセルに制限されず、場合によっては完全に小さくなる場合もあります。現時点では、解決策の 1 つは、以前に生成された小さな画像を強制的に大きくすることです。ただし、ブロードバンドでは十分に滑らかに見えません。その他の重要な問題はもちろんですが、さらに美しい生成方法をいくつか紹介します。
session_start();
$width=600; 🎜>if($height $height=$width / 4;
$sourcestrings="0123456789aqwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";
//オブジェクトを作成します
$image=imagecreate($) width,$height);
$white=imagecolorallocate($image,255,255,255);
imagefill($image,0,0,$white);
$fonts= dirname(__FILE__);
putenv('"gdfontpath=".$fonts=.""');
$font_size=floor($height / 2); 🎜>//文字列を取得します
unset($sessionval);
$strsize=rand(5,8);
for($i=0;$i$i_temp=rand(1,62);
$sessionval .=$sourcestrings[$i_temp];
$x_i =$font_size $i *$width / ($strsize 1); y_i = $height / 2;
$angle_i=rand(-120,120);
$fontcolor_a=imagecolorallocate($image,rand(0,255),rand(0,255)); ($image,$font_size,$angle_i,$x_i,$y_i,$fontcolor_a,$fontname,$sourcestrings[$i_temp])
}
unset($_SESSION['cjjer']); >$_SESSION['cjjer'] = $sessionval;
//ノイズの数
for($i=0;$i{
$i_x=rand(0,$width);
$i_y=rand(0,$height);
imagesetpixel($image,$i_x,$i_y,imagecolorallocate($image,rand(0,255), rand(0,2550),rand(0,255)));
//オブジェクト
header('content-type:image/png');
imagedestroy($image);

オンラインテスト: http://www.phzzy.org/temp/5do8/ex6_login.php
解説:
まず、幅と高さ、高さが小さすぎて文字が表示されません。ランダムに抽出されたものと同じ文字がいくつかあります:
$sourcestrings="0123456789aqwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";
オブジェクトを作成し、白で塗りつぶします:
$image=imagecreate($width,$height) ;
$white=imagecolorallocate($ image,255,255,255);
imagefill($image,0,0,$white);
$fonts を確認したいフォントを読み込みます。 = dirname(__FILE__);//現在のルート ディレクトリに戻り、ここにフォント ファイルをコピーします。フォント ファイルは *.ttf ファイルです。
putenv('"gdfontpath=".$fonts=.""');
$fontname='arial';
文字の高さを定義します。ここでは高さの半分に設定します。
$font_size=floor($height / 2);
変数をクリアして、生成される文字数:
unset($sessionval);
$strsize=rand(5,8);
ループ、文字を 1 つずつ入力します:
このループの文字列を取得します。変数の後に追加してセッションに書き込みます。
$i_temp =rand(1,62);
$sourcestrings[$i_temp];
に書き込まれた文字列の位置を取得します。画像 (x および y 座標)
$x_i =$font_size $i *$width / ($strsize 1);
$y_i = $height / 2; 正面から見たときの傾きを設定します。 .
$angle_i=rand(-120,120);
色をランダムに生成します。
$fontcolor_a=imagecolorallocate($image,rand(0,255),rand(0,255));画像に書き込む;
imageTTFText($angle_i,$x_i,$y_i,$fontcolor_a,$fontname,$sourcestrings[$i_temp]);
この関数についてご質問がある場合は、関連情報を確認してください。
セッションへの書き込み、サイド登録コードの使用:
$_SESSION['cjjer'] = $sessionval ;
ノイズの追加:
//ノイズの数
for($i=0;$i{
$i_x=rand (0,$width);
$i_y=rand(0,$ height);
imagesetpixel($image,$i_x,$i_y,imagecolorallocate($image,rand(0,255),rand(0,2550) ),rand(0,255)));
ヘッダーへの出力:
header('content-type:image/png');//この行は、デフォルトで出力できる png 画像であることを示します。画像のヘッダー形式ではありません
imagepng( $image);
imagedestroy($image);
独自のフォント ライブラリをロードして、回転角度を設定できます $angle_i=rand(-120,120);フォントの高さ $font_size=floor($height / 2) ; フォントの色 $fontcolor_a と乱数の数: $strsize=rand(5,8); 例 6: 画像に透かしを入れてサムネイルを生成します
従来の ASP ページのウォーターマーク サムネイルの生成は比較的面倒で、他のコンポーネントが使用されるのが一般的ですが、ご想像のとおり、PHP では 30 行未満のプログラムで簡単に実行できます。 :
$source="my.jpg";
$zoom=0.5;
$str='私はイケメンです、あなたはMMですか?'; >$ image=imagecreatefromjpeg($source);
$width=images($image);
$color_red=imagecolorallocate($image,111,0,0) ); //レッド
$font=dirname(__FILE__);
$str=iconv('GB2312','UTF-8',$str); fontsize= 30;
$fromx=$width/5;
$fromy=$height/2; ,$ fromy,$color_red,$font,$str);
$width_temp=imagesx($image) * $zoom;
$height_temp=imagesy($image) *
$img= imagecreatetruecolor( $width_temp,$height_temp);
imagecopyresize ($img,$image,0,0,0,0,$width_temp, $height_temp,$width,$height);
imagedestroy($image);
$file_zoomname="my_zoom_jpeg.jpg";
imagedestroy($img);
生成された jpg image :
元の画像は 70K ですが、gif を生成するとファイルは 18K を超え、png では 76K を使用するため、
コード分析でサムネイルを生成します。 :
ここで最初に設定します。 いくつかのパラメータ:
$source="my.jpg"; //ソース画像
$zoom=0.5; //ズーム率
$str='ハンサムな男、あなたは女の子ですか?' // ウォーターマーク テキスト
ソース画像を読み込みます (ウォーターマークなし、読み込みなし):
$image=imagecreatefromjpeg($source); 長さと幅のサイズを取得します。 :
$width=imagesx( $image);
$height=imagesy($image);
中国語を使用しているため、中国語のフォント ライブラリをインポートする必要があります。実行できない場合、コードが文字化けするため、文字列エンコードを変換する必要があります
$font=dirname(__FILE__) "//simsun.ttc"; 'UTF-8',$str);
開始点、フォント サイズ、パースペクティブを設定します:
$fontsize=30;
$fromx= $width/5;
$fromy=$height/2;
imagettftext ($image,$fontsize,$angle,$fromx,$fromy,$font,$str);ズーム サイズの要件に応じた新しいサイズのオブジェクト:
$width_temp=imagesx($image ) * $zoom;
$height_temp=imagesy($image) * $zoom; $width_temp,$height_temp);
ソース画像を gd ライブラリの imagecopyresize にコピーします。 自動的にサイズ変更します。
imagecopyresize ($img,$image,0,0,0,0,$width_temp, $height_temp) ,$width,$height);
小さな画像を生成し、オブジェクトをクリアします。
$file_zoomname="my_zoom_jpeg.jpg"; file_zoomname);
imagedestroy($img);
サムネイルの生成、透かしの一般的なコア技術です。

声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、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衣類リムーバー

Video Face Swap

Video Face Swap

完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

ホットツール

SublimeText3 Linux 新バージョン

SublimeText3 Linux 新バージョン

SublimeText3 Linux 最新バージョン

VSCode Windows 64 ビットのダウンロード

VSCode Windows 64 ビットのダウンロード

Microsoft によって発売された無料で強力な IDE エディター

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

このプロジェクトは osdn.net/projects/mingw に移行中です。引き続きそこでフォローしていただけます。 MinGW: GNU Compiler Collection (GCC) のネイティブ Windows ポートであり、ネイティブ Windows アプリケーションを構築するための自由に配布可能なインポート ライブラリとヘッダー ファイルであり、C99 機能をサポートする MSVC ランタイムの拡張機能が含まれています。すべての MinGW ソフトウェアは 64 ビット Windows プラットフォームで実行できます。

Dreamweaver Mac版

Dreamweaver Mac版

ビジュアル Web 開発ツール

DVWA

DVWA

Damn Vulnerable Web App (DVWA) は、非常に脆弱な PHP/MySQL Web アプリケーションです。その主な目的は、セキュリティ専門家が法的環境でスキルとツールをテストするのに役立ち、Web 開発者が Web アプリケーションを保護するプロセスをより深く理解できるようにし、教師/生徒が教室環境で Web アプリケーションを教え/学習できるようにすることです。安全。 DVWA の目標は、シンプルでわかりやすいインターフェイスを通じて、さまざまな難易度で最も一般的な Web 脆弱性のいくつかを実践することです。このソフトウェアは、