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

[Feature request] Resize images to prevent data usage #616

Closed
prom00 opened this issue Sep 13, 2024 · 8 comments
Closed

[Feature request] Resize images to prevent data usage #616

prom00 opened this issue Sep 13, 2024 · 8 comments
Assignees
Labels
pending release fix in place, pending release

Comments

@prom00
Copy link

prom00 commented Sep 13, 2024

I've noticed that my backup is 10mb when I created 5 cars in the system where only 2 of them contain an image.
After looking inside the backup, I've noticed the images haven't been resized.

Maybe it's nice to resize the images to save storage space?

@prom00 prom00 changed the title Resize images to prevent data usage [Feature request] Resize images to prevent data usage Sep 13, 2024
@hargata hargata self-assigned this Sep 16, 2024
@hargata
Copy link
Owner

hargata commented Sep 16, 2024

Spent about 20-30 minutes on this, resizing is possible but the quality is pretty bad, see screenshot below, left is without resizing and right is with resizing.

image

Resizing on the fly is pretty tricky because the app needs to balance speed and quality. Otherwise it's going to spend upwards of 30 seconds trying to resize an image if we were to try a sampling technique that can preserve more quality. There are also a few occasions where the resized image was actually larger in file size compared to the original image which used JPEG compression.

Test results between an image resized on paint.net(left) vs on-the-fly resizing in LubeLogger(right)
image
Left: 13.7KB, Right: 128KB, both were resized down to 109x145

FWIW, there are a dozen different photo editors out there that can do a far better job at resizing images and IMO it falls out of scope for LubeLogger to try to tackle this challenge, BUT I am going to keep this ticket open just in case I happen to stumble upon an efficient image library down the road since this would be a pretty neat feature to have.

Just to give you an idea of how many sampling techniques there are out there:
image

@prom00
Copy link
Author

prom00 commented Sep 17, 2024

Awesome you're looking into this!

In my system, the image is 186 x 145
image

The original image size is now 4032 x 3024
I've now resized the image to 672 x 504

This is still looking perfectly:
image

The image size has changed from 4.43MB to 206kB.

What I do in PHP is using the following: https://www.php.net/manual/en/function.imagecopyresized.php

imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

I input the uploaded image and the output (resized) image I save on disk to use for all future use.

I have no experience in C to do this unfortunately, but I've asked our big AI friend, if he can help us out. He came up with this:

#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"

#define STB_IMAGE_RESIZE_IMPLEMENTATION
#include "stb_image_resize.h"

#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image_write.h"

#include <stdio.h>
#include <stdlib.h>

int main() {
    int width, height, channels;
    
    // Load the image
    unsigned char *img = stbi_load("input.jpg", &width, &height, &channels, 0);
    if (img == NULL) {
        printf("Error loading image\n");
        return 1;
    }

    // New dimensions for the resized image
    int new_width = 200;
    int new_height = 200;

    // Allocate memory for the resized image
    unsigned char *resized_img = (unsigned char *)malloc(new_width * new_height * channels);

    // Resize the image
    stbir_resize_uint8(img, width, height, 0, resized_img, new_width, new_height, 0, channels);

    // Save the resized image
    stbi_write_jpg("output_resized.jpg", new_width, new_height, channels, resized_img, 100);

    // Free the memory
    stbi_image_free(img);
    free(resized_img);

    return 0;
}

@hargata hargata added the pending release fix in place, pending release label Oct 17, 2024
@hargata
Copy link
Owner

hargata commented Oct 31, 2024

Released.

@hargata hargata closed this as completed Oct 31, 2024
@prom00
Copy link
Author

prom00 commented Nov 1, 2024

Awesome! I'd love to update my installation, but I'm a bit scared of losing everything.

Is there somewhere a description on how to update a running configuration without loosing everything?
I know I can make a backup and reload it, but it feels like this isn't the way to go?

Is it posible we move all data to a volume maybe?
Sorry I'm new to docker....

@hargata
Copy link
Owner

hargata commented Nov 1, 2024

The docker compose should include all the volumes that needs configured.

@prom00
Copy link
Author

prom00 commented Nov 1, 2024

I have a docker-compose like this:

services:
  lubelogger:
    image: hargata/lubelogger
    ports:
      - "8080:8080"
    env_file:
      - /pathToEnvFile/lubelogger.env
    restart: unless-stopped
    volumes:
      - myapp:/home/node/app  # use named volume


volumes:
  myapp:

Note that I added a volume. However it doesn't matter if I add it or dont'. Whenever I run those commands:

docker stop <container>
docker rm <container>
docker compose up -d

It starts a container with an updated version of lubelogger (that's great)
But I have to reload the backup manually when I go to my browser at ipaddress:8080.
All settings are gone and also all vehicles etc.

When I restore a backup, everything is fine again.

@hargata
Copy link
Owner

hargata commented Nov 1, 2024

Your volume does not map to the directories used by the app, refer to the docker-compose.yml file found in this repository.

@prom00
Copy link
Author

prom00 commented Nov 5, 2024

That works alot better! Thanks alot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending release fix in place, pending release
Projects
None yet
Development

No branches or pull requests

2 participants