Skip to content

Commit

Permalink
Merge pull request #123 from codelitdev/issue-118-2
Browse files Browse the repository at this point in the history
Thumbnail optimization
  • Loading branch information
rajat1saxena authored Apr 8, 2024
2 parents 063a5b7 + 34b30ff commit f52d459
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion apps/api/src/config/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const APIKEY_RESTRICTION_CUSTOM = "custom";
export const tempFileDirForUploads = process.env.TEMP_FILE_DIR_FOR_UPLOADS;
export const maxFileUploadSize = process.env.MAX_UPLOAD_SIZE || 2147483648;
export const imagePattern = /^image\/(jpe?g|png)$/;
export const imagePatternIncludingGif = /^image\/(jpe?g|png|gif)$/;
export const imagePatternIncludingGif = /^image\/(jpe?g|png|gif|webp)$/;
export const videoPattern = /video/;
export const cloudEndpoint = process.env.CLOUD_ENDPOINT || "";
export const cloudRegion = process.env.CLOUD_REGION || "";
Expand Down
12 changes: 7 additions & 5 deletions packages/thumbnail/bin/generate-thumbnail.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
input_image="$1"
# Output thumbnail path
output_thumbnail="$2"
# Crop the image to 16:9 if necessary and resize to a lower resolution if height > desired_height, otherwise keep original height
desired_height=${3:-480}

# Check if input image is provided
if [[ -z "$input_image" ]]; then
Expand All @@ -25,12 +27,12 @@ else
target_width=$width
fi

# Crop the image to 16:9 if necessary and resize to 720p if height > 720, otherwise keep original height
if [ $target_height -le 720 ]; then
final_height=$target_height

if [ $target_height -le $desired_height ]; then
final_height=$target_height
else
final_height=720
target_width=$((final_height * 16 / 9))
final_height=$desired_height
target_width=$((final_height * 16 / 9))
fi

# Generate the thumbnail
Expand Down

0 comments on commit f52d459

Please sign in to comment.