Sticker Book

2007-08-14 by xpheas
I found a really cool book - the "Free Software Sicker Book".



"This book includes a set of stickers related to free software projects. Now, you may remove Microsoft sticker from your computer (computers are only not designed for the Microsoft Windows) and choose some sticker of this book to replace it."

Here's the link to the Projekt Page:
http://www.pikao.nierox.com/

  » comments (0)

GraphicsMagick and PHP

2007-08-11 by xpheas
I wrote a small command line PHP script using the GraphicsMagick library to scale down a lot of pictures.
The script creates a scaled down version from the original picture and a thumbnail.
Optionally the script can generate hyperlinks and bbcods.

First the PHP sourcecode:

PHP-Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/php
<?php
#{
    //input directory - the origenal pictures
    $dir_in = "./in/";
 
    //output directory - the new pictures and thumbnails
    $dir_out = "./out/";
 
    //new picture size
    $base_size = "1536x1024";
 
    //thumbnail size
    $thumb_size = "150x150";
 
    //url where the pictures are stored on the web
    $url = "http://your.web/path_to_picture_dir_with_ending_slash/";
 
    //how many pictures per row?
    $pics_per_row = 3;
 
 
    /////////////////////////////////////////////////////////////////////////////
    $files = array();
    $dh = opendir($dir_in);
    while(($file = readdir($dh))!==false)
    {
      if($file!="." && $file!="..")
      {
	$_fn = strtolower($file);
	$_fn = str_replace(array(" ", "%20"), "_", $_fn);
	$_fn = preg_replace("/[^a-z0-9\.]/", "", $_fn);
 
	$files[$_fn] = $file; 
      }
    }
    closedir($dh);
 
    $cnt_files = count($files);
    $cnt = 1;
    foreach($files as $key=>$val)
    {
      if(!file_exists($dir_out.$key))
      {
	$_sys = "gm convert -size ".$base_size." ".$dir_in.$val." ".$dir_out.$key;
	//print $_sys."\n";
	exec($_sys);
      }
      if(!file_exists($dir_out."t_".$key))
      {
	$_sys = "gm convert -size ".$thumb_size." ".$dir_in.$val." -resize ".$thumb_size." +profile \"*\" ".$dir_out."t_".$key;
	//print $_sys."\n";
	exec($_sys);
      }
 
      print "\nthumbnailing ".$val." - ".$cnt."/".$cnt_files;
      $cnt++;
    }
 
    if($url)
    {
      $cnt = 1;
      $links = array();
      foreach($files as $key=>$val)
      {
	$links[0] .= "<a href=\"".$url.$key."\"><img src=\"".$url."t_".$key."\" border=\"0\" alt=\"".$key."\" /></a>".($cnt<$pics_per_row ? " " : "<b />\n");
	$links[1] .= "[url=".$url.$key."][img]".$url."t_".$key."[/img][/url]".($cnt<$pics_per_row ? " " : "\n");
 
	if($cnt==$pics_per_row) $cnt = 1;
	else $cnt++;
      }
 
      $fh = fopen("links.txt", "w+");
      fwrite($fh, $links[0]."\n\n".$links[1]);
      fclose($fh);
    }
 
    print "\ndone\n";
 
?>



Set up the config variables:

$dir_in - relative or absolute path to the pictures you wish to convert
$dir_out - relative or absolute path to the new pictures and thumbnails
$base_size - the new max picture size
$thumb_size - thumbnail size

Optionally - if you wish links and bbcodes:

$url - the full url (with ending shlash) to the folder, where the pictures are stored on the web.
$pics_per_row - line-break (<br />) after ?? pictures


If you don't have installed the GraphicsMagick library, you can install it under ubuntu
by typing "sudo-apt get install graphicsmagick". (the universe repository must be activated)


Usage - from unix shell:

Save the script i.e. as gm.php.
Make it executable - "chmod a+x gm.php".
Rund the script by typing "./gm.php"

  » comments (0)