2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【PHP】(あー、画像をバラバラにしてタイル状に並べて、出力してぇ)

Last updated at Posted at 2014-10-24

ということがよくあるかと思います。

まず、「超画像魂コンバイン」というフリーソフトを使って1枚の画像を分割します。

縦横30で分割した場合、ファイルが保存されるときの命名規則は、下記のようになります。

x0,y0 x1,y0 x2,y0 ・・・ x29,y0
・・・ ・・・ ・・・ ・・・ ・・・
x0,y29 ・・・ ・・・ ・・・ x29,y29

名前順でソートすると、左の一列から順にファイルが表示されます。

フリーソフトで画像を出力しようと試みましたが、命名規則の問題で縦横の表示がうまくいかず断念。

phpのfor文を使って表示することに。

<ul>

<?php

for($x = 0;$x < 30; $x++) {

    echo '<li>';

    for($y = 0;$y < 30; $y++) {
        echo '<img src="hoge_x' . $x . '_y' . $y . '.jpg"><br>'  ;
    }

    echo '</li>';
}

?>

</ul>

あとは、cssで調整して出力すれば完成。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?