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

[Feat] - Image Resizer #48

Merged
merged 24 commits into from
Sep 12, 2024
Merged

Conversation

EduardoDePatta
Copy link
Contributor

Hello again!

This PR introduces a new Image Resizer page that allows users to resize images in PNG, JPEG, and SVG formats. Supports aspect ratio maintenance, and quality adjustments(jpeg).

Key Changes

  1. Utility Functions:
    - Added resizeImage, processImageFile, updateWidth, and updateHeight functions to handle image resizing and dimension
    adjustments.

  2. New Component:
    - Implemented the ImageResize component, which lets users upload, resize, and download images.

  3. Test Suite:
    - Added tests to ensure correct functionality, especially for aspect ratio and format handling.

  4. Updated Tools List:
    - New tool accessible from the main tools page.

  5. Documentation update:
    - The README file was updated to include the new tool in the list of available utilities, with a direct link.

Benefits

  1. Efficiency: Simplifies image resizing for web development and content creation.
  2. Performance: Helps reduce image file sizes, improving load times.
  3. Compatibility: Ensures images are optimized for different devices.

OBS: canvas in devDependencies

1. Added canvas to devDependencies to simulate the canvas API in Node.js during testing.
2. If canvas is removed, related tests must also be removed.

I also considered adding the functionality to crop images, but since this PR is already QUITE LARGE due to the extensive test file, the addition of dependencies, and the refactoring of the image upload component to make it reusable, SEO component, etc, I decided to leave that as a separate task, should this one be approved.

- Added  directive to ensure the component is handled as client-side component
@peckz
Copy link
Collaborator

peckz commented Aug 29, 2024

Thank you @EduardoDePatta, I'm on vacation until 9th September, after that I'm going to have a look!

@EduardoDePatta EduardoDePatta changed the title [Feature] - Image Resizer [Feat] - Image Resizer Sep 3, 2024
pages/utilities/image-resizer.tsx Outdated Show resolved Hide resolved
pages/utilities/image-resizer.tsx Outdated Show resolved Hide resolved
pages/utilities/image-resizer.tsx Outdated Show resolved Hide resolved
pages/utilities/image-to-base64.tsx Show resolved Hide resolved
pages/utilities/image-resizer.tsx Show resolved Hide resolved
@peckz
Copy link
Collaborator

peckz commented Sep 10, 2024

@EduardoDePatta This looks very solid! I tweaked structure to be more aligned with other tools in latest commit.
Also, I added max height for preview image since it can happen that users upload vertical screenshot (from mobile)

I left few minor comments for you to address.


This is the preview of updated UI / structure:

image

@peckz
Copy link
Collaborator

peckz commented Sep 10, 2024

@EduardoDePatta I also noticed that tests are failing for Image resizer

FAIL components/utils/resize-image.utils.test.ts (10.528 s)

- rename variables for clarity
- add dynamic resizing information
- display dynamic labels
- implement quality input validations
- set maximum file size
- update UI labels and elements
- improve code maintainability
@EduardoDePatta
Copy link
Contributor Author

@EduardoDePatta I also noticed that tests are failing for Image resizer

FAIL components/utils/resize-image.utils.test.ts (10.528 s)

@peckz the test likely failed because the canvas package is not installed as a dev dependency. Since jsdom doesn't fully support .toDataUrl, the canvas package is required to simulate this behaviour in a node.js environment using jest.
Installing the necessary dependencies should resolve the issue.

Aside from that, all the other corrections have already been made!

@peckz
Copy link
Collaborator

peckz commented Sep 11, 2024

@EduardoDePatta Thanks for resolving conflicts!
I'm having issues with npm install. I've run into this before with node-canvas package.

From their repo:

Compiling
If you don't have a supported OS or processor architecture, or you use --build-from-source, the module will be compiled on your system. This requires several dependencies, including Cairo and Pango.

For detailed installation information, see the wiki. One-line installation instructions for common OSes are below. Note that libgif/giflib, librsvg and libjpeg are optional and only required if you need GIF, SVG and JPEG support, respectively. Cairo v1.10.0 or later is required.

I might need to update README.md with additional steps.

Which OS are you using Windows, Linux, Mac?
Are you using node 20.9.0

@EduardoDePatta
Copy link
Contributor Author

@peckz I tested it on both Ubuntu 22.04.3 and Windows 10, without npm cache and with node 20.9.0 and everything worked fine! I wasn't able to reproduce the issue you reported. If it's possible to identify where the problem occours, we could create a postinstall script with uname or something similar to add the necessary dependencies for specific environments.

@peckz
Copy link
Collaborator

peckz commented Sep 12, 2024

@EduardoDePatta Thanks for info! I think in general, the problem is with MacOS and arm architecture.
Our pipeline is running npm install successfully on linux-x64 node-20.9.0-linux-x64.tar.gz

Those libs are necessary to install on MacOS:

brew install pkg-config cairo pango libpng jpeg giflib librsvg pixman python-setuptools

I'm going to merge this and update README.md

Thank you for the contribution!

@peckz peckz merged commit 0a90875 into jamdotdev:main Sep 12, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants