| 1 | #!/usr/bin/php5 |
| 2 | <?php |
| 3 | |
| 4 | require_once 'connect.db.inc.php'; |
| 5 | |
| 6 | $globals->debug = 0; // Do not store backtraces. |
| 7 | $MAX_X = 200; |
| 8 | $MAX_Y = 100; |
| 9 | |
| 10 | $it = XDB::rawIterator('SELECT id, diminutif, logo, logo_mime |
| 11 | FROM groups |
| 12 | WHERE logo IS NOT NULL AND logo != ""'); |
| 13 | |
| 14 | while ($row = $it->next()) { |
| 15 | $group_id = $row['id']; |
| 16 | $group_name = $row['diminutif']; |
| 17 | $logo = $row['logo']; |
| 18 | $mime = $row['mime']; |
| 19 | $img = imagecreatefromstring($logo); |
| 20 | if ($img === false) { |
| 21 | print "\n\nError reading image for:\n $group_name\n\n"; |
| 22 | continue; |
| 23 | } |
| 24 | $x = imagesx($img); |
| 25 | $y = imagesy($img); |
| 26 | $nx = $x; |
| 27 | $ny = $y; |
| 28 | if ($x > $MAX_X || $y > $MAX_Y) { |
| 29 | if ($x > $MAX_X) { |
| 30 | $ny = intval($y * $MAX_X / $x); |
| 31 | $nx = $MAX_X; |
| 32 | } |
| 33 | if ($y > $MAX_Y) { |
| 34 | $nx = intval($x*$MAX_Y/$y); |
| 35 | $ny = $MAX_Y; |
| 36 | } |
| 37 | $img2 = imagecreatetruecolor($nx, $ny); |
| 38 | imagealphablending($img2, false); |
| 39 | imagesavealpha($img2,true); |
| 40 | $transparent = imagecolorallocatealpha($img2, 255, 255, 255, 127); |
| 41 | imagefilledrectangle($img2, 0, 0, $nx, $ny, $transparent); |
| 42 | imagecopyresampled($img2, $img, 0, 0, 0, 0, $nx, $ny, $x, $y); |
| 43 | $tmpf = tempnam('/tmp', 'upgrade_111_group_logos'); |
| 44 | imagepng($img2, $tmpf); |
| 45 | $f = fopen($tmpf, 'r'); |
| 46 | $logo2 = fread($f, filesize($tmpf)); |
| 47 | fclose($f); |
| 48 | unlink($tmpf); |
| 49 | XDB::execute("UPDATE groups |
| 50 | SET logo = {?}, logo_mime = 'image/png' |
| 51 | WHERE id = {?}", $logo2, $group_id); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | |
| 56 | |