Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 32 additions & 14 deletions api/applyEffects.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,6 @@
]));
}

$imageResource = imagecreatefromjpeg($filename_tmp);

if (!$imageResource) {
die(json_encode([
'error' => 'Could not read jpeg file. Are you taking raws?',
]));
}

if (!isset($_POST['filter'])) {
die(json_encode([
Expand All @@ -58,40 +51,65 @@

$image_filter = false;

if (!empty($_POST['filter']) && $_POST['filter'] !== 'imgPlain') {
if (!empty($_POST['filter']) && $_POST['filter'] !== FILTER_PLAIN) {
$image_filter = $_POST['filter'];
}

// apply filter
if ($image_filter) {
applyFilter($image_filter, $imageResource);
applyFilter($image_filter, createImageResource($imageResource, $filename_tmp));
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me this makes the code less readable.

}

if ($config['polaroid_effect']) {
$polaroid_rotation = $config['polaroid_rotation'];

$imageResource = effectPolaroid($imageResource, $polaroid_rotation, 200, 200, 200);
$imageResource = effectPolaroid(createImageResource($imageResource, $filename_tmp), $polaroid_rotation, 200, 200, 200);
}

if ($config['chroma_keying']) {
$chromaCopyResource = resizeImage($imageResource, 1500, 1000);
$chromaCopyResource = resizeImage(createImageResource($imageResource, $filename_tmp), 1500, 1000);

imagejpeg($chromaCopyResource, $filename_keying, $config['jpeg_quality_chroma']);
imagedestroy($chromaCopyResource);
}

if (empty($imageResource)) {
if (!copy($filename_tmp, $filename_photo)) {
die(json_encode([
'error' => 'Image copy failed'
]));
}
} else {
imagejpeg($imageResource, $filename_photo, $config['jpeg_quality_image']);
}


// image scale, create thumbnail
$thumbResource = resizeImage($imageResource, 500, 500);
$thumbResource = resizeImage(createImageResource($imageResource, $filename_tmp), 500, 500);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are always creating a thumbnail and therefore we always have to create a image resource.



imagejpeg($thumbResource, $filename_thumb, $config['jpeg_quality_thumb']);
imagedestroy($thumbResource);

imagejpeg($imageResource, $filename_photo, $config['jpeg_quality_image']);
imagedestroy($imageResource);
if (!empty($imageResource)) imagedestroy($imageResource);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point $imageResource is always not empty.


// insert into database
appendImageToDB($file);

echo json_encode([
'file' => $file,
]);


function createImageResource(&$imageResource, $path) {

if(empty($imageResource)) {
$imageResource = imagecreatefromjpeg($path);
if (!$imageResource) {
die(json_encode([
'error' => 'Could not read jpeg file. Are you taking raws?',
]));
}
}
return $imageResource;
}