Skip to content

Commit 87718ba

Browse files
authored
Merge pull request #5 from metimol/copilot/fix-db03113a-7947-417a-af85-702b7aab36de
Fix pixel upscaling to add 4000 pixels to both width and height independently
2 parents f139310 + 9603a66 commit 87718ba

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

src/utils/imageProcessor.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export interface ProcessedImage {
1414
}
1515

1616
/**
17-
* Calculate target dimensions to add exactly 4000 pixels while maintaining aspect ratio
17+
* Calculate target dimensions to add exactly 4000 pixels to both width and height
1818
*/
1919
function calculateTargetDimensions(originalWidth: number, originalHeight: number): {
2020
newWidth: number;
@@ -23,18 +23,17 @@ function calculateTargetDimensions(originalWidth: number, originalHeight: number
2323
pixelsAdded: number;
2424
} {
2525
const originalPixels = originalWidth * originalHeight;
26-
const targetPixels = originalPixels + 4000;
2726

28-
// Calculate scale factor to achieve target pixels while maintaining aspect ratio
29-
const scaleFactor = Math.sqrt(targetPixels / originalPixels);
27+
// Add 4000 pixels to both width and height
28+
const newWidth = originalWidth + 4000;
29+
const newHeight = originalHeight + 4000;
3030

31-
// Calculate new dimensions
32-
const newWidth = Math.round(originalWidth * scaleFactor);
33-
const newHeight = Math.round(originalHeight * scaleFactor);
34-
35-
// Calculate actual pixels added (may be slightly different due to rounding)
31+
// Calculate actual pixels added
3632
const actualPixelsAdded = (newWidth * newHeight) - originalPixels;
3733

34+
// Calculate overall scale factor for display purposes
35+
const scaleFactor = Math.sqrt((newWidth * newHeight) / originalPixels);
36+
3837
return {
3938
newWidth,
4039
newHeight,

0 commit comments

Comments
 (0)