Archive for September, 2009

Calculate image aspect ratio in PHP

Posted in PHP on September 13th, 2009 by Ilir Fekaj – 1 Comment

Calculating image aspect ratio in PHP is very simple. First you need to find greatest common divisor(GCD). You can do that by using following function:

function GCD($a, $b) {
while ($b != 0)
$remainder = $a % $b;
$a = $b;
$b = $remainder;
}
return abs ($a);
}

If you compiled your PHP version with GMP functions, you can also use following:

$gcd = gmp_gcd($a, $b);

After finding GCD, simply divide both sides with it:

$a = 2048; // screen width
$b = 1152; // screen height
$gcd = GCD($a, $b);
$a = $a/$gcd;
$b = $b/$gcd;
$ratio = $a . ":" . $b;

Post to Twitter Tweet This Post

WallpapersDB – another DB project

Posted in Projects on September 13th, 2009 by Ilir Fekaj – Be the first to comment


After more than three and a half years of no new projects, finally next site in my planned DB series – WallpapersDB – Desktop Wallpapers is ready to meet the world. As its name may suggest, this one is meant to help you in your efforts to beautify your computer screens.

Like with my previous avatars site(actually like with all sites I built in last years), this one is built around PHP/MySQL technology. I used my new favourite two column CSS layout with 310 pixels wide right column which can hold medium rectangle ad and plenty of info. For thumbnail generation and other image manipulation I used powerful Imagemagick. I find it easier to use and results are very good. All image manipulations are cached on server to speed up whole process.

Like with all sites these days; you can register, comment, upload, share and do all kind of neat stuff new web offers. You can browse wallpapers by category or native resolution. Thumbnails are big and when you choose wallpaper, script will generate image optimized for your screen size.

Post to Twitter Tweet This Post