#------------------------------------------------------------------------------- # Arquivo: aspect_ratio.config # # # Descrição: Script para calcular a razão de aspecto (fracionária e decimal) # baseado nas tags "ImageWidth" e "ImageHeight" de uma imagem. # Também determina o formato da imagem: quadrado, retrato ou # paisagem. Com atalhos curtos. # # # Notas: Ver https://en.wikipedia.org/wiki/Aspect_ratio_(image) definição # do "Aspect Ratio". # # # Exemplos: # > exiftool -config aspect_ratio.config -imagesize -AspectRatio \ # -AspectRatioDecimalFormat -AspectRatioProportionFactor \ # -LayoutOrientation image.png # -AspectRatio -AspectRatioDecimalFormat -AspectRatioProportionFactor \ # -LayoutOrientation # # Image Size : 1920x1440 # Aspect Ratio : 4:3 # Aspect Ratio Decimal Format : 1.33:1 # Aspect Ratio Factor Proportion : 1.333 # Layout Orientation : Landscape # # > exiftool -config aspect_ratio.config -ImageSize -ImageSize -AR -ARDF \ # -ARPF -LTO image.png # -AR -ARDF -ARPF -LTO # # Image Size : 100x100 # Aspect Ratio : 1:1 # Aspect Ratio Decimal Format : 1:1 # Aspect Ratio Proportion Factor : 1.0000 # Layout Orientation : Square # # # Testes/Simulações: # > magick -size 3840x1574 xc:white jpg:- | exiftool -config \ # aspect_ratio.config -ImageSize -AspectRatio -AspectRatioDecimalFormat \ # -AspectRatioProportionFactor -LayoutOrientation - # # > magick -size 3840x1574 xc:white jpg:- | exiftool -config \ # aspect_ratio.config -ImageSize -aspectratio -aspectratiodecimalformat \ # -aspectratioproportionfactor -layoutorientation - # # > magick -size 3840x1574 xc:white jpg:- | exiftool \ # -config aspect_ratio.config -ImageSize -AR -ARDF -ARPF -LTO - # # > magick -size 3840x1574 xc:white 3840x1574.jpg | exiftool -config \ # aspect_ratio.config -ImageSize -AspectRatio -AspectRatioDecimalFormat \ # -AspectRatioProportionFactor -LayoutOrientation - # # # https://www.unravel.com.au/aspect-ratio-cheat-sheet, no caso de vídeos \ # "486p (NTSC D1 SD)". # > ffmpeg -y -f lavfi -i color=c=white:s=720x576:d=1 -aspect 16:9 -c:v \ # libx264 -pix_fmt yuv420p -loglevel quiet /tmp/out.m4v && exiftool \ # -config aspect_ratio.config -ImageSize -AR -ARDF -ARPF -LTO \ # /tmp/out.m4v && rm /tmp/out.m4v # > ffmpeg -y -f lavfi -i color=c=white:s=720x486:d=1 -aspect 4:3 -c:v \ # libx264 -pix_fmt yuv420p -loglevel quiet /tmp/out.m4v && exiftool \ # -config aspect_ratio.config -ImageSize -AR -ARDF -ARPF -LTO \ # /tmp/out.m4v && rm /tmp/out.m4v # # # Ano/Mês/Dia # Reviews: 2024/02/20 - Christian W. Correa Created # 2024/02/21 - Added a list of Aspect Ratio standard values to # the ImageFormat tag # 2024/09/05 - ArchZu Reescrito \ # Editado: gcd, AspectRatio, ImageFormat. \ # Adicionado: AspectRatio AspectRatioDecimalFormat \ # AspectRatioProportionFactor LayoutOrientation # #------------------------------------------------------------------------------- # Mapear atalhos curtos para as tags %Image::ExifTool::UserDefined::Shortcuts = ( 'AR' => 'AspectRatio', 'ARDF' => 'AspectRatioDecimalFormat', 'ARPF' => 'AspectRatioProportionFactor', 'LTO' => 'LayoutOrientation', ); # Função para calcular o Máximo Divisor Comum (MDC) sub gcd { my ($a, $b) = @_; return $b == 0 ? $a : gcd($b, $a % $b); } %Image::ExifTool::UserDefined = ( 'Image::ExifTool::Composite' => { # Razão de aspecto fracionária AspectRatio => { Require => { 0 => 'ImageWidth', 1 => 'ImageHeight', }, ValueConv => q{ my $width = $val[0]; my $height = $val[1]; # Calcular MDC my $gcd = gcd($width, $height); # Calcular a razão fracionária my $numerator = $width / $gcd; my $denominator = $height / $gcd; return "$numerator:$denominator"; }, }, # Razão de aspecto no formato decimal AspectRatioDecimalFormat => { Require => { 0 => 'ImageWidth', 1 => 'ImageHeight', }, ValueConv => q{ my $width = $val[0]; my $height = $val[1]; # Dividir o primeiro valor pelo segundo my $result = sprintf("%.3f", $width / $height); $result =~ s/\d$//; # Remove o último dígito $result .= ":1"; # Adiciona ":1" ao final return $result; }, }, # Fator de proporção da razão de aspecto AspectRatioProportionFactor => { Require => { 0 => 'ImageWidth', 1 => 'ImageHeight', }, ValueConv => q{ my $width = $val[0]; my $height = $val[1]; # Dividir o primeiro valor pelo segundo return sprintf("%.3f", $width / $height); }, }, # Orientação da imagem LayoutOrientation => { Require => { 0 => 'ImageWidth', 1 => 'ImageHeight', }, ValueConv => q{ my $width = $val[0]; my $height = $val[1]; # Determinar a orientação com base no aspecto da imagem if ($width == $height) { return 'Square'; # Quadrado } elsif ($width > $height) { return 'Landscape'; # Paisagem } else { return 'Portrait'; # Retrato } }, }, }, ); 1; # Fim do arquivo