Skip to content
Merged
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
18 changes: 13 additions & 5 deletions packages/utility/src/image.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import imageCompression from 'browser-image-compression';
import { DefaultSettings } from '@onlook/constants';
import { normalizePath } from './folder';
import imageCompression from 'browser-image-compression';
import { isImageFile } from './file';
import { normalizePath } from './folder';

// Browser-side image compression
export async function compressImageInBrowser(file: File): Promise<string | undefined> {
export async function compressImageInBrowser(
file: File,
compressionOptions?: {
maxSizeMB?: number;
maxWidthOrHeight?: number;
quality?: number;
}
): Promise<string | undefined> {
const options = {
maxSizeMB: 2,
maxWidthOrHeight: 2048,
maxSizeMB: compressionOptions?.maxSizeMB ?? 0.2,
maxWidthOrHeight: compressionOptions?.maxWidthOrHeight ?? 512,
quality: compressionOptions?.quality ?? 0.6,
Comment on lines +16 to +18
Copy link
Contributor

Choose a reason for hiding this comment

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

There appears to be a discrepancy between the PR description and implementation. The PR description states that the default compression values should be:

  • maxSizeMB: 2
  • maxWidthOrHeight: 2048
  • quality: 0.8

However, the implementation sets more aggressive defaults:

  • maxSizeMB: 0.2
  • maxWidthOrHeight: 512
  • quality: 0.6

These more aggressive defaults will result in smaller file sizes but potentially lower image quality than what was specified in the PR description. Consider aligning the implementation with the documented defaults to ensure consistent behavior.

Suggested change
maxSizeMB: compressionOptions?.maxSizeMB ?? 0.2,
maxWidthOrHeight: compressionOptions?.maxWidthOrHeight ?? 512,
quality: compressionOptions?.quality ?? 0.6,
maxSizeMB: compressionOptions?.maxSizeMB ?? 2,
maxWidthOrHeight: compressionOptions?.maxWidthOrHeight ?? 2048,
quality: compressionOptions?.quality ?? 0.8,

Spotted by Diamond

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

};

try {
Expand Down