Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Do not alter pictures unless filters applied #186

Closed
wants to merge 1 commit into from
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
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
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
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;
}