gd ライブラリの画像ダウンロード クラスは、Web ページ上のすべての画像をダウンロードするための PHP コードを実装します。
PHP コードは次のとおりです:
コードをコピー コードは次のとおりです:
header ("コンテンツタイプ: text/html ; charset=utf-8");
if (!empty($_POST['submit'])){
$url = $_POST['url'];
//相対パスを使用して画像を取得する操作の場合
$url_fields = parse_url($url);
$main_url = $url_fields['host'];
$base_url = substr($url, 0,strrpos( $url, '/') 1);
//Web コンテンツを取得
//プロキシ サーバーを設定
$opts = array('http'=>array('request_fulluri'= >true) );
$context = stream_context_create($opts);
$content = file_get_contents($url,false,$context);
//img タグを照合し、一致する文字列をすべて保存します配列 $matches
$reg = "//i";
preg_match_all($reg, $content, $matches) ;
$count = count($matches[0]);
for ($i=0; $i/*すべての画像 URL を小文字に変換します
*$matches[1][$i] = strto lower($matches[1][$i]);
*/
//画像が相対パスの場合はフルパスに変換します
if (!strpos( 'a'.$matches[1][$i], 'http')){
//'/' は 0 番目の位置なので
if (strpos('a'. $matches[1] [$i], '/')){
$matches[1][$i] = 'http://'.$main_url.$matches[1][$i]; 🎜>}else{
$matches[1][$i] = $base_url.$matches[1][$i]
}
}
}
// 重複をフィルターします画像
$img_arr = array_unique($matches[1]);
//画像ダウンロード クラスをインスタンス化します
$getImg = new DownImage();
$url_count = count($img_arr); 🎜>for ( $i=0; $i$getImg->source = $img_arr[$i];
$getImg->save_address = './pic /';
$file = $getImg->download();
}
echo "ダウンロードが完了しました!ハハ、シンプルにしてください! ";
}
class DownImage{
public $source;//リモート画像 URL
public $save_address;//ローカルアドレスを保存
public $set_extension; //画像拡張子を設定
public $quality; //画質(0~100、100が最高、デフォルトは75程度)
//ダウンロード方法(GDライブラリイメージダウンロードを選択)
public function download() {
// リモート画像情報を取得します
$info = @getimagesize($this->source);
// 画像拡張子を取得します
$mime = $info['mime'];
$type = substr(strrchr($mime, '/'), 1);
//画像タイプごとに異なる画像生成および保存関数を選択します
switch($type){
case 'jpeg':
$img_create_func = 'imagecreatefromjpeg';
$new_img_ext = 'jpg';
$image_quality = isset($this->quality); $this-> 品質 : 100;
break;
ケース 'png':
$img_save_func = 'imagepng'; ';
ブレーク;
ケース 'bmp':
$img_save_func = 'imagebmp';
ケース ' gif':
$img_create_func = 'imagegif';
$new_img_ext = 'gif';
ケース 'vnd. wap.wbmp':
$img_create_func = 'imagecreatefromwbmp';
$new_img_ext = 'bmp';
case 'xbm'; >$img_create_func = '
$img_save_func = 'imagexbm';
$new_img_ext = 'xbm';
デフォルト:
$img_save_func = ' imagejpeg';
$new_img_ext = 'jpg';
}
//拡張子が設定されているかどうかに応じてローカル ファイル名を合成します
if (isset($this->set_extension) ){
$ext = strrchr($this->source,".");
$strlen = strlen($ext); ,0,- $strlen)).'.'.$new_img_ext;
}else{
$newname = Basename($this->source);
//ローカル ファイル パスを生成します
$save_address = $this->save_address.$newname;
$img = @$img_create_func($this->source);
if (isset($image_quality))
$ save_img = @$img_save_func($img,$save_address,$image_quality);
}else{
$save_img = @$img_save_func($img,$save_address);
return $save_img;
}
?>

ホットAIツール

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

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

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

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

人気の記事

ホットツール

Dreamweaver Mac版
ビジュアル Web 開発ツール

SublimeText3 英語版
推奨: Win バージョン、コードプロンプトをサポート!

メモ帳++7.3.1
使いやすく無料のコードエディター

AtomエディタMac版ダウンロード
最も人気のあるオープンソースエディター

SAP NetWeaver Server Adapter for Eclipse
Eclipse を SAP NetWeaver アプリケーション サーバーと統合します。
