2013年12月24日火曜日

FCKeditor 久々にいじってみた

何度も利用したことがあるのですが、久々に組み込んでみた。

本家の方はどんどんバージョンアップしていくが、ファイルマネージャが有料なので、フォークした日本版を使う。 メンテナーのかたはおひとりで奮闘されています。感謝です。

http://sourceforge.jp/projects/fckeditor/

エディタの高さがうまく調節できなかったのでですが、結局全画面で編集すれば済みます。

ツールバーもたくさんありすぎるので、カスタマイズします。


2013年12月19日木曜日

2013年12月13日金曜日

GD で png 画像を透過、リサイズ

http://yoo-s.com/topic/detail/388

function resize_image($org_path, $new_path, $to_width, $to_height) {
    list($org_width , $org_height) = getimagesize($org_image_path);
    $src_image = imagecreatefrompng($org_path);
 
    $rate = 1;
    if ($org_width > $org_height) {
        $rate = $to_width / $org_width;
    } elseif ($org_width < $org_height) {
        $rate = $to_height / $org_height;
    } else {
        if ($to_width > $to_height) {
            $rate = $to_height / $org_height;
        } else {
            $rate = $to_width / $org_width;
        }
    }
    $to_width = $rate * $org_width;
    $to_height = $rate * $org_height;
 
    // 再サンプル
    $new_image = imagecreatetruecolor($to_width, $to_height);
    imagealphablending($new_image, false);
    imagesavealpha($new_image, true);
 
    imagecopyresampled($new_image, $src_image, 0, 0, 0, 0, $to_width, $to_height, $org_width, $org_height);
 
    imagepng($new_image, $new_image_path);
 
    imagedestroy($src_image);
    imagedestroy($new_image);
}
 
 
png 透過の手順は、
(1) imagecreatetruecolor() で画像作成
(2) imagealphablending(), imagesavealpha() でアルファチャンネルの作成
(3) imagepng() で画像の書き出し

リサイズの手順は
(1) getimagesize() で取得したサイズ配列から
(2) 比率を計算(サンプルの計算はちょっとあやしいかも)
(3) imagecopyresampled() でリサンプリング