<?php

function makeimage($items) {
	global $im_path, $userData, $cardID, $cdir, $base_dir;
/*
	$cmd = $im_path . ' ' . $base_dir . '/images/full/6c712a9.jpg -font "' . $base_dir . '/fonts/arial.ttf"  -pointsize 29 -density 300 -draw "gravity NorthWest fill #00ffcc text 370,340 \'Company Name\'" -units pixelsperinch ' . $base_dir . '/images/res_test.png 2>&1';
	exec($cmd, $out, $ret);
	print_r($out);
	print_r($ret);
	die;
	*/
	$koef = 4.18;
	$file_in = $base_dir . '/images/full/6c712a9.jpg';
	$font_path = $base_dir . '/fonts/';
	$out_file = $cdir . 'rendered_front_test.png';
	$cmd = array();
	foreach ($items as $item) {
		$cmd[] = '-font "' . $font_path . strtolower($item->font . '.ttf') . '" -pointsize ' . $item->size . ' -density 300 -draw "gravity NorthWest fill #' . substr('000000' . dechex($item->color), -6) . ' text ' . ((float)$item->x * $koef + 1/8 * 300 * 2) . ',' . ((float)$item->y * $koef + 1/8 * 300 * 2) . ' \'' . $item->text . '\'"';
	}
	
	echo $cmd_base = $im_path . ' ' . $file_in . ' ' . implode(' ', $cmd) . ' -units pixelsperinch ' . $out_file;
	exec($cmd_base, $out, $ret);
	print_r($out);
	print_r($ret);
}