From fb2da733b79bceef9c24a04f5bec141451a9645e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Barrois?= Date: Mon, 9 May 2011 22:07:21 +0200 Subject: [PATCH] Add script for resizing group logos. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Raphaël Barrois --- upgrade/1.1.1/group_logos.php | 56 +++++++++++++++++++++++++++++++++++++++++++ upgrade/1.1.1/update.sh | 3 +++ 2 files changed, 59 insertions(+) create mode 100755 upgrade/1.1.1/group_logos.php diff --git a/upgrade/1.1.1/group_logos.php b/upgrade/1.1.1/group_logos.php new file mode 100755 index 0000000..b95a046 --- /dev/null +++ b/upgrade/1.1.1/group_logos.php @@ -0,0 +1,56 @@ +#!/usr/bin/php5 +debug = 0; // Do not store backtraces. +$MAX_X = 200; +$MAX_Y = 100; + +$it = XDB::rawIterator('SELECT id, diminutif, logo, logo_mime + FROM groups + WHERE logo IS NOT NULL AND logo != ""'); + +while ($row = $it->next()) { + $group_id = $row['id']; + $group_name = $row['diminutif']; + $logo = $row['logo']; + $mime = $row['mime']; + $img = imagecreatefromstring($logo); + if ($img === false) { + print "\n\nError reading image for:\n $group_name\n\n"; + continue; + } + $x = imagesx($img); + $y = imagesy($img); + $nx = $x; + $ny = $y; + if ($x > $MAX_X || $y > $MAX_Y) { + if ($x > $MAX_X) { + $ny = intval($y * $MAX_X / $x); + $nx = $MAX_X; + } + if ($y > $MAX_Y) { + $nx = intval($x*$MAX_Y/$y); + $ny = $MAX_Y; + } + $img2 = imagecreatetruecolor($nx, $ny); + imagealphablending($img2, false); + imagesavealpha($img2,true); + $transparent = imagecolorallocatealpha($img2, 255, 255, 255, 127); + imagefilledrectangle($img2, 0, 0, $nx, $ny, $transparent); + imagecopyresampled($img2, $img, 0, 0, 0, 0, $nx, $ny, $x, $y); + $tmpf = tempnam('/tmp', 'upgrade_111_group_logos'); + imagepng($img2, $tmpf); + $f = fopen($tmpf, 'r'); + $logo2 = fread($f, filesize($tmpf)); + fclose($f); + unlink($tmpf); + XDB::execute("UPDATE groups + SET logo = {?}, logo_mime = 'image/png' + WHERE id = {?}", $logo2, $group_id); + } +} + + + diff --git a/upgrade/1.1.1/update.sh b/upgrade/1.1.1/update.sh index 9230e34..6269d56 100755 --- a/upgrade/1.1.1/update.sh +++ b/upgrade/1.1.1/update.sh @@ -7,3 +7,6 @@ confirm "* Running database upgrade scripts" mysql_run_directory . + +confirm "* Running upgrade scripts" +script_run ./group_logos.php -- 2.1.4