From: Raphaël Barrois Date: Mon, 9 May 2011 20:07:21 +0000 (+0200) Subject: Add script for resizing group logos. X-Git-Tag: xorg/1.1.1~2 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=fb2da733b79bceef9c24a04f5bec141451a9645e;p=platal.git Add script for resizing group logos. Signed-off-by: Raphaël Barrois --- 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