function design($images, $border = '', $effect = '', $saveDir = '', $copyLast = false, $output = 'data')
{
$id = isset($images[0]['design']) && $images[0]['design'] ? $images[0]['design'] : mt_rand();
$color = strlen($images[0]['color']) == 7 ? substr($images[0]['color'], 1) : $images[0]['color'];
$new_image = ($saveDir ? $saveDir : 'cache/') . 'Design-' . $id . '.png';
$path = '';
$directories = explode('/', dirname(str_replace('../', '', $new_image)));
foreach ($directories as $directory) {
$path = $path . '/' . $directory;
if (!file_exists(DIR_IMAGE . $path)) {
@mkdir(DIR_IMAGE . $path, 0777);
}
}
$image = new Image(DIR_IMAGE . $images[0]['src']);
$width = $images[0]['width'];
$height = $images[0]['height'];
$image->resize($width, $height, '', $color);
if ($images[0]['rotation']) {
$image->rotate($images[0]['rotation'] * -1);
$rotate = $images[0]['rotation'];
}
// Look for image Mask, to trim stuff outside the target area.
$imagesrc = substr($images[0]['src'], 0, -4) . '-' . $images[0]['rotation'] . substr($images[0]['src'], -4);
if (file_exists(DIR_IMAGE . $imagesrc)) {
$images[0]['width'] = $image->getInfo('width');
$images[0]['height'] = $image->getInfo('height');
$images[0]['mask'] = 1;
$images[0]['src'] = $imagesrc;
$images[0]['rotation'] = 0;
}
if ($copyLast || isset($images[0]['mask'])) {
// Cover the top of the image with the base image
$images[0]['left'] = $images[0]['top'] = 0;
$images[] = $images[0];
}
unset($images[0]);
foreach ($images as $i => $img) {
$image_temp = new Image(DIR_IMAGE . $img['src']);
$size = isset($img['size']) && $img['size'] ? $img['size'] / 100 : 1;
if ($img['type'] != 'text') {
if (isset($images[$i]['crop']) && strpos($images[$i]['crop'], '/')) {
$crop = explode('/', $images[$i]['crop']);
$ratio = isset($crop[4]) ? $image_temp->getInfo('width') > $image_temp->getInfo('height') ? $image_temp->getInfo('width') / $crop[4] : $image_temp->getInfo('height') / $crop[4] : 1;
$image_temp->crop($crop[0] * $ratio, $crop[1] * $ratio, $crop[2] * $ratio, $crop[3] * $ratio);
}
$image_temp->resize($img['width'] * $size, $img['height'] * $size, isset($img['mask']) ? '' : $effect);
if ($img['rotation']) {
$image_temp->rotate($img['rotation'] * -1);
}
} else {
$image_temp->text($img['src'], $img['font'], DESIGN_TEXT_DEFAULT_SIZE * $size, DESIGN_FONT_COLOR, '', $img['rotation'] * -1);
}
$imgLeft = isset($img['left']) ? (int) $img['left'] : 0;
$imgTop = isset($img['top']) ? (int) $img['top'] : 0;
$opacity = $img['type'] != 'mainProduct' ? 80 : 100;
$image->merge($image_temp->getResource(), $imgLeft, $imgTop, $opacity);
}
/*if ($rotate) {
$image->rotate($rotate);
$cx = $image->getInfo('width')/2;
$cy = $image->getInfo('height')/2;
$image->crop($cx - ($width/2),$cy - ($height/2), $cx + ($width/2),$cy + ($height/2));
$image->rotate($rotate*-1);*/
$width = $image->getInfo('width');
$height = $image->getInfo('height');
//}
$image->resize($width, $height, $border, $color);
if ($output == 'data') {
return $image->getData(DIR_IMAGE . $new_image);
} else {
$image->save(DIR_IMAGE . $new_image);
if ($this->request->server['HTTPS']) {
return $this->config->get('config_ssl') . 'image/' . $new_image;
} else {
return $this->config->get('config_url') . 'image/' . $new_image;
}
}
}