-2

私はコードを使用しています。このコードは、最初にフォルダー内のファイル名をチェックしてから、URLを作成します。URLで、それがimagefileである特別な行を見つけます。画像と住所は正しく表示されますが、画像が大きすぎると時間がかかります。画像の代わりにサムネイルを作成して表示することはできますか?ありがとう!

require_once('simple_html_dom.php');
$files = scandir('files/');
foreach($files as $file) {
    if($file == '.' || $file == '..') continue;
    $file = basename($file, ".html");
    $url = 'http://address.com/test/'.$file;
    $html = file_get_html($url);
foreach($html->find('img') as $element) {
    if (strpos($element,'address.com') !== false) {
    $url = $element->src;
    echo $url.'</br>';
    echo '<IMG SRC="',$url, '" WIDTH="128" HEIGHT="96" BORDER="0" ALT="" /><br/>';
    }
    }
}
4

2 に答える 2

0

CSSを使いたいclip:rect(50px 218px 155px 82px);

幅と高さを設定しても実際の画像サイズは減少しないため、読み込み時間は同じくらい長くかかります。ステップバイステップdivの作成とcssコーディングについては、この記事を参照してください。

http://www.seifi.org/css/creating-thumbnails-using-the-css-clip-property.html

また、サイドノートとして、実際に作成するTUMBNAILSに勝るものはありません!サーブ側のサムネイル ジェネレーターもありますが、これは実際に tumbnails を作成しなくても得られる最高のものです。

于 2013-02-19T15:29:35.837 に答える
0

アップロードされた画像のサイズを比例的に変更する方法に関するブログ投稿を書きました。私が書いたサンプルのコードを調整して、必要なことを実行できるはずです。

将来、サイトが停止した場合に備えて、以下のコードを貼り付けます。

<?php

// *snip* Removed form stuff
$image = imagecreatefromjpeg($pathToImage);


// Target dimensions
$max_width = 240;
$max_height = 180;


// Calculate new dimensions
$old_width      = imagesx($image);
$old_height     = imagesy($image);
$scale          = min($max_width/$old_width, $max_height/$old_height);
$new_width      = ceil($scale*$old_width);
$new_height     = ceil($scale*$old_height);


// Create new empty image
$new = imagecreatetruecolor($new_width, $new_height);


// Resample old into new
imagecopyresampled($new, $image, 
        0, 0, 0, 0, 
        $new_width, $new_height, $old_width, $old_height);


// Catch the image data
ob_start();
imagejpeg($new, NULL, 90);
$data = ob_get_clean();


// Destroy resources
imagedestroy($image);
imagedestroy($new);


// Output image data
header("Content-type: image/jpeg", true, 200);
echo $data;

おそらく、これを関数に貼り付けて、出力をファイルに変更したいと思うでしょう。次に、foreach ループでサムネイルを生成し、元のサムネイルの代わりにサムネイルにリンクします。また、画像ごとに複数回作成しないように、画像のサムネイルを既に作成しているかどうかも確認する必要があります。

于 2014-12-08T11:22:18.437 に答える