LoginSignup
2
2

More than 5 years have passed since last update.

php + imagick でチェック柄の画像を生成する

Last updated at Posted at 2012-12-26

おしゃれなかんじを演出したい気持ちになったので、さくっとそれっぽいコードを書いてみました。
これで作った画像を background に指定すると、こういう感じになります。
https://burberryplaid-php.herokuapp.com/

この index.html では background: url(image.php) fixed という指定をしてあります。

で、その image.php の中身はこんなかんじです。

image.php
<?php

require __DIR__ . '/../vendor/autoload.php';

$colors = [
  '#CBFF8C',
  '#E3E36A',
  '#C16200',
  '#881600',
  '#4E0110',
];

shuffle($colors);

use BurberryPlaid\Image;

$generator = new Image();

try {
  $image = $generator->generate(100, 100, array_slice($colors, 0 , 3));

  header('Content-type: image/png');
  echo $image;

  $image->destroy();
} catch (Exception $e) {
  echo $e->getMessage();
}

で、実際に画像を生成しているのはこんなんです。 GitHub に置いておきました。
https://github.com/riaf/burberryplaid-php


参考記事: http://colorburned.com/2008/11/create_a_burberry_style_plaid.html

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