Created
June 7, 2025 01:52
-
-
Save novogrammer/7964ffb02aa70ae164de36640c501232 to your computer and use it in GitHub Desktop.
画像の解像度を調べてCSSのwidthとheightを表示する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| scale=1 # デフォルト値 | |
| while getopts "s:" opt; do | |
| case "$opt" in | |
| s) scale="$OPTARG" ;; | |
| esac | |
| done | |
| shift $((OPTIND - 1)) | |
| file="$1" | |
| if [[ -z "$file" || ! -f "$file" ]]; then | |
| echo "Usage: $0 [-s scale] image_file" | |
| exit 1 | |
| fi | |
| width=$(identify -format "%w" "$file") | |
| height=$(identify -format "%h" "$file") | |
| scaled_width=$(printf "%.0f" "$(echo "$width * $scale" | bc)") | |
| scaled_height=$(printf "%.0f" "$(echo "$height * $scale" | bc)") | |
| echo "background-image: url('$file');" | |
| echo "width: ${scaled_width}px;" | |
| echo "height: ${scaled_height}px;" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment