ACC SHELL
<?php
define("PEREX_IMAGE_WIDTH", 150); // default perex width
define("PEREX_IMAGE_HEIGHT", 120); // default perex height
define("THUMB_MAX_WIDTH", 300); // maximum width of the thumbnail
define("THUMB_MAX_HEIGHT", 300); // maximum height of the thumbnail
define("IMAGE_MAX_WIDTH", 640); // maximum width of the scaled-down image
define("IMAGE_MAX_HEIGHT", 640); // maximum height of the scaled-down image
function open_image($filename)
{
$im = @imagecreatefromjpeg($filename);
if($im !== false)
return $im;
$im = @imagecreatefrompng($filename);
if($im !== false)
return $im;
$im = @imagecreatefromgif($filename);
if($im !== false)
return $im;
return false;
}
function clean_up($filename)
{
}
function resize_image($x1, $y1, $x2, $y2, $max_width, $max_height, &$image)
{
$width = abs($x1 - $x2);
$height = abs($y1 - $y2);
// calculate the resulting image size
$safety_break = 0;
while(1)
{
// if the image is small enough in both coordinates, then break
if($max_width / $width >= 1.0 && $max_height / $height >= 1.0)
break;
$coef = min($max_width / $width, $max_height / $height);
// multiplying both coords by the same coef won't change aspect ratio
$width *= $coef;
$height *= $coef;
// just to make sure
$safety_break++;
if($safety_break > 2)
die("Nepodarilo se spravne zmenit velikost obrazku");
}
// create the new image and resample it
$new_image = imagecreatetruecolor($width, $height);
imagecopyresampled(
$new_image,
$image,
0, 0,
min($x1, $x2), min($y1, $y2),
$width, $height,
abs($x1 - $x2),
abs($y1 - $y2)
);
return $new_image;
}
function create_perex($x1, $y1, $x2, $y2)
{
if(abs($x1 - $x2) < 3 || abs($y1 - $y2) < 3)
{
admin_msgbox("Výběr pro perex byl příliš malý, není možné pokračovat");
die();
}
$perex_image = imagecreatetruecolor(PEREX_IMAGE_WIDTH, PEREX_IMAGE_HEIGHT);
// load the original
$preview = open_image("../gfx/temp/preview" . get_filename());
$original = open_image("../gfx/temp/orig" . get_filename());
$coef = imagesx($original) / imagesx($preview);
$preview = NULL;
$x1 *= $coef;
$y1 *= $coef;
$x2 *= $coef;
$y2 *= $coef;
imagecopyresampled(
$perex_image,
$original,
0, 0, // dest top left corner
min($x1, $x2), min($y1, $y2), // source top left corner
PEREX_IMAGE_WIDTH, PEREX_IMAGE_HEIGHT, // dest size
abs($x1 - $x2), abs($y1 - $y2)
);
imagejpeg($perex_image, "../gfx/temp/" . get_filename() . "_perex.jpg");
}
function crop_image($x1, $y1, $x2, $y2)
{
// load the original
$preview = open_image("../gfx/temp/preview" . get_filename());
$original = open_image("../gfx/temp/orig" . get_filename());
$coef = imagesx($original) / imagesx($preview);
// handle some of the degenerate cases (handles the -1,-1,-1,-1 case as well)
if(abs($x1 - $x2) < 3 || abs($y1 - $y2) < 3 )
{
admin_display_warning("Výběr je příliš malý nebo nebyl vůbec aplikován, obrázek si zachová svojí původní velikost");
$x1 = $y1 = 0;
$x2 = imagesx($original);
$y2 = imagesy($original);
// the user didn't choose, no scaling to be done
$coef = 1.0;
}
$preview = NULL;
$x1 *= $coef;
$y1 *= $coef;
$x2 *= $coef;
$y2 *= $coef;
// create the cropped picture
$cropped = imagecreatetruecolor(abs($x2 - $x1), abs($y2 - $y1));
imagecopyresampled(
$cropped,
$original,
0, 0, // dest to
min($x1, $x2), min($y1, $y2), // src from
abs($x2 - $x1), abs($y2 - $y1), // dest size
abs($x2 - $x1), abs($y2 - $y1) // src size
);
//imagejpeg($cropped, "../gfx/temp/cropped.jpg");
$original = NULL;
// create thumb from cropped
$thumb = resize_image(
0, 0,
imagesx($cropped), imagesy($cropped),
THUMB_MAX_WIDTH,
THUMB_MAX_HEIGHT,
$cropped
);
imagejpeg($thumb, "../gfx/temp/" . get_filename() . "_thumb.jpg");
// create smaller image from cropped
$smaller = resize_image(
0, 0,
imagesx($cropped), imagesy($cropped),
IMAGE_MAX_WIDTH,
IMAGE_MAX_HEIGHT,
$cropped
);
imagejpeg($smaller, "../gfx/temp/" . get_filename() . ".jpg");
}
?>
ACC SHELL 2018