Victory Road  

Go Back   Victory Road > General > Technology
FAQ Community Today's Posts Search

Notices

 
 
Search this Thread
  #1  
Old February 20, 2009, 08:46:28 PM
SpaceMan++'s Avatar
SpaceMan++ SpaceMan++ is offline
Zoroark
 
Join Date: Aug 2008
Location: BC
Posts: 288
Default PHP Image List

Here is a script that I've used to put all banners to one big image.
This script put all(.png) images in a certain folder to one big image, this script uses greedy algorithm(http://en.wikipedia.org/wiki/Word_wrap#Algorithm ) of word wrapping.
Code:
#!/usr/bin/php
<?php

//please edit.
//width of the image.
$Width = 2500;
//height of the image
$Height = 2500;
//padding between all images.
$padding = 15;


$x = $padding;
$y = $padding;
$max = 0;

$image = imagecreatetruecolor($Width, $Height);
$col = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
imagefilledrectangle($image, 0, 0, imagesx($image), imagesy($image), $col);

$files = explode("\n", `ls *.png`);

foreach ($files as $file)
{
	if (file_exists($file))
	{
		$copy = imagecreatefrompng($file);
		if (!is_resource($copy))
		{
			continue;
		}
		$sx = imagesx($copy);
		$sy = imagesy($copy);
		
		if ($x + $sx > imagesx($image))
		{
			$y += $max;
			$x = $padding;
		}
		imagecopy($image, $copy, $x, $y, 0, 0, $sx, $sy);
		$x += $sx + $padding;
		if ($sy > $max)
		{
			$max = $sy + $padding;
		}
		imagedestroy($copy);
	}
}

imagepng($image);
imagedestroy($image);
?>
It must be run on a Linux server such as freehostia and buizel.net
To use the script, edit the first few lines to change the options.
Here is something I've generated with that script:
http://spacemanplusplus.deviantart.com/ ... -113279109
 

Forum Jump


All times are GMT -8.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Victory Road ©2006 - 2024, Scott Cat333Pokémon Cheney
Theme by A'bom and Cat333Pokémon