2

Web サイトでページが更新されるたびに新しい背景画像を表示するにはどうすればよいですか (これが役立つ場合は Wordpress を使用します)。また、さまざまな画面解像度と、これに対する適切な処理も考慮に入れたいと思います。どんな助けでも大歓迎です。

4

6 に答える 6

1

WordPress コーデックスでこのページを見たことがありますか?

ヘッダー画像を回転させる方法を説明します。ニーズに合わせて調整するのはそれほど難しいことではありません。

于 2009-08-04T16:51:39.057 に答える
1

アクセスするたびに画像をランダムに返す独自のスクリプトを用意してください。以下の URL に C で書いたものがあり、毎回異なる画像を返します。

http://www.scale18.com/cgi-bin/gpic

于 2009-08-04T17:03:05.697 に答える
0

これは、Wordpressでサイトのヘッダー画像をランダムに回転させるために使用するものです。

他の誰かがコードを書いたのですが、誰なのか思い出せません。以下のphpコードをrotate.phpという名前のファイルに入れ、次にrotate.phpを回転する画像のディレクトリ(つまり「headerimages」)に入れると、rotate.phpがそれらから描画します。ヘッダーイメージに使用されているDIVを使用して、CSSスタイルシートからrotate.phpを呼び出します。

さまざまな画面解像度を処理できるということの意味がわかりません。エンドユーザーの画面解像度?

<?php


/*

    Call this way: <img src="http://example.com/rotate.php">


    Set $folder to the full path to the location of your images.
    For example: $folder = '/user/me/example.com/images/';
    If the rotate.php file will be in the same folder as your
    images then you should leave it set to $folder = '.';

*/


    $folder = '.';


    $extList = array();
    $extList['gif'] = 'image/gif';
    $extList['jpg'] = 'image/jpeg';
    $extList['jpeg'] = 'image/jpeg';
    $extList['png'] = 'image/png';


$img = null;

if (substr($folder,-1) != '/') {
    $folder = $folder.'/';
}

if (isset($_GET['img'])) {
    $imageInfo = pathinfo($_GET['img']);
    if (
        isset( $extList[ strtolower( $imageInfo['extension'] ) ] ) &&
        file_exists( $folder.$imageInfo['basename'] )
    ) {
        $img = $folder.$imageInfo['basename'];
    }
} else {
    $fileList = array();
    $handle = opendir($folder);
    while ( false !== ( $file = readdir($handle) ) ) {
        $file_info = pathinfo($file);
        if (
            isset( $extList[ strtolower( $file_info['extension'] ) ] )
        ) {
            $fileList[] = $file;
        }
    }
    closedir($handle);

    if (count($fileList) > 0) {
        $imageNumber = time() % count($fileList);
        $img = $folder.$fileList[$imageNumber];
    }
}

if ($img!=null) {
    $imageInfo = pathinfo($img);
    $contentType = 'Content-type: '.$extList[ $imageInfo['extension'] ];
    header ($contentType);
    readfile($img);
} else {
    if ( function_exists('imagecreate') ) {
        header ("Content-type: image/png");
        $im = @imagecreate (100, 100)
            or die ("Cannot initialize new GD image stream");
        $background_color = imagecolorallocate ($im, 255, 255, 255);
        $text_color = imagecolorallocate ($im, 0,0,0);
        imagestring ($im, 2, 5, 5,  "IMAGE ERROR", $text_color);
        imagepng ($im);
        imagedestroy($im);
    }
}

?>
于 2009-08-04T17:42:08.490 に答える
0

GDライブラリでリアルタイムに生成できます

于 2009-08-04T16:32:25.010 に答える
0

画面解像度を検出するには、クライアント側の JavaScript を使用できます

screen.height
screen.width

別の画像を表示するには、おそらくスクリプトを使用して乱数を生成し、それに関連付けられた画像を表示することができます...? 「現在の」画像をセッションに保存し、新しい乱数を生成するたびに、最後の画像が表示されないことを確認することができます....

于 2009-08-04T16:32:52.857 に答える
-1

JavaScript がおそらくこれに最適です。

于 2009-08-04T16:30:36.073 に答える