mozshot の最近のブログ記事
何かとサイトサムネイルで重宝するMozshotですが、
サムネイル表示のために、毎回URLの指定やソースの調整をすることがだんだん苦になってきました。
簡単にサイトサムネルを表示するファンクションのサンプルがあったので自分なりに改造し、
指定URLのタイトル取得とMozshotのサムネイルにリンクを組み合わせてみました。
<?php
/*---- 指定したURLのソースを取得 ----*/
function getURL( $pURL ) {
$_data = null;
if( $_http = @fopen( $pURL, "r" ) ) {
while( !feof( $_http ) ) {
$_data .= fgets( $_http, 1024 );
}
fclose( $_http );
}
return( $_data );
}
/*---- ソース内にある余計な改行コードを取り除く----*/
function cleanString( $pString ) {
$_data = str_replace( array( chr(10), chr(13), chr(9) ), chr(32), $pString );
while( strpos( $_data, str_repeat( chr(32), 2 ), 0 ) != false ) {
$_data = str_replace( str_repeat( chr(32), 2 ), chr(32), $_data );
}
return( trim( $_data ) );
}
/*---- 指定した最初タグ内にある文字列を取得 ----*/
function getElement( $pElement, $pSource ) {
//取得できなかった場合の代替テキスト
if(empty($pSource)){
$pSource = chr(60).$pElement.chr(62)."Pages".chr(60)."/".$pElement.chr(62);
}
$_data = null;
$pElement = strtolower( $pElement );
$_start = strpos( strtolower( $pSource ), chr(60) . $pElement, 0 );
$_start = strpos( $pSource, chr(62), $_start ) + 1;
$_stop = strpos( strtolower( $pSource ), "</" . $pElement . chr(62), $_start );
if( $_start > strlen( $pElement ) && $_stop > $_start ) {
$_data = trim( substr( $pSource, $_start, $_stop - $_start ) );
}
return( $_data );
}
/*---- Mozshot用ファンクション ---*/
function mShot($url,$s){
if ($url) {
$sData = getURL( $url );
$sData = cleanString( $sData );
$sData = getElement( "title", $sData );
mb_language( 'Japanese' );
$title = mb_convert_encoding($sData, "UTF-8", "auto");
}
$imgSize[0] = '64';
$imgSize[1] = '128';
$imgSize[2] = '256';
$thumbUrl[0] = "/small";
$thumbUrl[1] = "";
$thumbUrl[2] = "/large";
$a = "<div id=¥"mShot¥"><a href=¥"".$url."¥" target=¥"_blank¥">¥n";
$a = $a."<strong class=¥"title¥">".$title."</strong><br />¥n";
$a = $a."<span class=¥"url¥">".$url."</span><br />¥n" ;
$a = $a."<img src=¥"http://mozshot.nemui.org/shot".$thumbUrl[$s]."?".$url."¥" width=¥"".$imgSize[$s]."¥" height=¥"".$imgSize[$s]."¥" alt=¥"".$title."¥" />¥n";
$a = $a."</a></div>¥n" ;
echo $a;
}
?>
上記のfunction.phpをサムネイル表示を使うページindex.phpでインクルードして使う。
<?php include_once $_SERVER['DOCUMENT_ROOT']."/include/function/function.php";?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Mozshotファンクションテスト</title>
<style type="text/css">
<!--
#mShot {
padding: 0px;
margin: 0px;
}
#mShot .title {
font-weight: bold;
}
#mShot .url {
font-size: small;
}
#mShot img {
border: none;
}
-->
</style>
</head>
<body>
<?php mShot("http://hoshiya.biz",0);?>
<?php mShot("http://hoshiya.biz",1);?>
<?php mShot("http://hoshiya.biz",2);?>
</body>
</html>
このサイト用のCSSを適用しているので、
色は違いますが、実際に表示すると
<?php mShot("http://hoshiya.biz",0);?>の場合
<?php mShot("http://hoshiya.biz",1);?>の場合
<?php mShot("http://hoshiya.biz",2);?>の場合
となります。
参考ページ
トラックバック(0)
トラックバックURL:
MozshotとCSSを組み合わせて
サイトのサムネイル画像の周りに文字を回り込ませて配置。
リンク集のページなどに便利です。
<style type="text/css">
/*画像の回り込みの設定*/
.imgLeft { float : left ; }
/*文字の回り込みの解除*/
.clrLeft { clear : both ; }
</style>
<div class="clrLeft">
<p class="imgLeft">
<img src="http://mozshot.nemui.org/shot/large?http://hoshiya.biz" alt="星屋工作室" />
星屋工作室
</p>
</div>
↓↓上記でこうなる↓↓
星屋工作室
このサイトのトラックバックにも使用しています。
トラックバック(0)
トラックバックURL:
指定のURLのサムネイルをリアルタイムに表示するツール。
以下のタグを例に「?」以降にURLを指定してやるだけ!
こんなツール待ってました。
サムネイルの表示の方法もいくつかあるようです。
説明のページ↓
上記ページの内容を参照
- Simple:
http://mozshot.nemui.org/shot?http://www.google.com/
- Get small (64x64) image:
http://mozshot.nemui.org/shot/small?http://www.google.com/
- Get large (256x256) image:
http://mozshot.nemui.org/shot/large?http://www.google.com/
- Get 800x600 image:
http://mozshot.nemui.org/shot/800x600?http://www.google.com/
- Set browser window size to 300x300:
http://mozshot.nemui.org/shot/-300x300?http://www.google.com/
- Specify window & image size:
http://mozshot.nemui.org/shot/800x800-800x800?http://www.google.com/
更に詳細設定も可能。
- uri 対象のURL
- noresize
- win_x
- win_y
- effect 影の有無 true:あり false:なし
- keepratio
トラックバック(0)
トラックバックURL:




