Skip to content

Instantly share code, notes, and snippets.

@anon987654321
Last active October 12, 2024 09:24
Show Gist options
  • Select an option

  • Save anon987654321/0ad7d8aa71990c82e9b7b3d92bdbec58 to your computer and use it in GitHub Desktop.

Select an option

Save anon987654321/0ad7d8aa71990c82e9b7b3d92bdbec58 to your computer and use it in GitHub Desktop.

Postpro - Analog Etterbehandling

Dette bildebehandlingsverktøyet bruker libvips for å emulere forskjellige analoge filtre og effekter. Verktøyet er designet for å tilføre en profesjonell, cinematisk og gjerne nostalgisk touch til digitale bilder, inspirert av klassiske filmutseender og profesjonell fargegradering brukt i filmindustrien.

Funksjoner

  • Bleach Bypass: Høykontrast, lav metning som gir et dramatisk uttrykk, brukt i actionfilmer.
  • Cross Processing: Øker farger og kontrast, etterligner feilaktig filmutvikling for en unik look, ofte sett i musikkvideoer.
  • Kodachrome: Inspirert av Kodaks ikoniske film med høy kontrast og mettede farger, perfekt for en retro følelse. Mer om Kodachrome.
  • Teal & Orange: En stil brukt i moderne filmer med komplementære farger for dynamikk.
  • Film Noir: Klassisk svart-hvitt med høy kontrast for en mystisk atmosfære, se film noir.
  • Classic Hollywood: Varme toner og myk kontrast som gir et glamorøst uttrykk.
  • Low Key: Mørk stil med høy kontrast, ofte brukt i skrekkfilmer.
  • High Key: Lys stil med lav kontrast som skaper en ren, positiv følelse.
  • Golden Age: Myke, varme toner inspirert av Hollywoods gullalder.
  • Pastel Cinematic: Subtile pastelltoner for en drømmende stemning.
  • Dark Academia: Dramatisk, mørk tone med kontrast som gir en intellektuell stemning.
  • Moody Tones: Dempede farger og sterk kontrast som gir emosjonell dybde.
  • Psychedelic Pop: Overmettede farger for et psykedelisk retro uttrykk.
  • Silver Screen: Klassisk filmstil med dempet kontrast.
  • Day for Night: Simulerer nattopptak gjort på dagtid.
  • Retro Futuristic: Fargesterk, vintage science-fiction estetikk.

Disse effektene kan ikke enkelt oppnås med vanlige verktøy eller mobilapper. Med libvips får du profesjonelle fargegraderinger og filmatiske effekter som gir bildene dine en autentisk kinoaktig kvalitet. Få andre verktøy kan tilby denne typen avansert etterbehandling.

Krav

  • OpenBSD 7.5
  • libvips (bruk doas pkg_add -U libvips for installasjon)
  • Ruby (versjon 3.3 eller høyere)

Installasjon

  1. Installer nødvendige avhengigheter:

     doas pkg_add -U libvips
    
  2. Kjør skriptet:

     ./postpro8.sh <input_bildebane> [<utdata_bildebane>] [<profil>]
    

    Erstatt <input_bildebane>, <utdata_bildebane>, og <profil> med riktige verdier. Tilgjengelige profiler inkluderer:

     - `bleach_bypass`
     - `cross_processing`
     - `kodachrome`
     - `teal_orange`
     - `film_noir`
     - `classic_hollywood`
     - `low_key`
     - `high_key`
     - `silver_screen`
     - `day_for_night`
     - `golden_age`
     - `pastel_cinematic`
     - `dark_academia`
     - `moody_tones`
     - `psychedelic_pop`
     - `retro_futuristic`
    

Bruk

For å bruke en bestemt stil på bildet ditt, må du oppgi bildebanen, utdata-plasseringen, og den ønskede profilen. For eksempel:

```sh
./postpro8.sh input.jpg output.jpg kodachrome
```

Dette vil bruke "Kodachrome"-profilen for å legge til en høy kontrast og mettet fargestil til inngangsbildet ditt.

Feilsøking

Hvis du får feil knyttet til vips.so.42, sørg for at symlinken til riktig bibliotek er satt opp:

```sh
doas ln -sf /usr/local/lib/libvips.so.42 /usr/local/lib/libvips.so
```

Du må kanskje også sette `LD_LIBRARY_PATH` til å inkludere nødvendige kataloger:

```sh
export LD_LIBRARY_PATH="/usr/local/lib:/usr/lib:/lib:${LD_LIBRARY_PATH}"
```

Notater

Dette verktøyet bruker libvips, et effektivt bildebehandlingsbibliotek som kan behandle store bildefiler med høy ytelse. Dette gir ressursbesparende behandling sammenlignet med tradisjonelle verktøy.

Føl deg fri til å eksperimentere med forskjellige profiler for å oppnå ønsket estetikk!

#!/bin/zsh
# Installerer libvips, et effektivt bildebehandlingsbibliotek
if ! command -v vips &> /dev/null; then
echo "libvips ikke funnet. Installerer libvips..."
doas pkg_add -U libvips
fi
if [[ ! -L /usr/local/lib/libvips.so ]]; then
echo "Oppretter symlink for libvips"
doas ln -sf /usr/local/lib/libvips.so.42 /usr/local/lib/libvips.so
fi
export LD_LIBRARY_PATH="$(echo /usr/local/lib:/usr/lib:/lib:$LD_LIBRARY_PATH | awk -v RS=: -v ORS=: '!a[$0]++' | sed 's/:$//')"
# Definerer forhåndsinnstilte profiler for analoge effekter
preset_profiles=(
"vintage_look"
"modern_cinema"
"noir_cinema"
"golden_hour"
"cyberpunk"
"teal_orange"
"bleach_bypass"
"cross_processing"
"kodachrome"
"cinematic_cool"
"desaturated_film"
"sepia_vintage"
"high_key"
"low_key"
"day_for_night"
"muted_pastels"
"hyper_reality"
"grunge_punk"
"neo_noir"
"silver_screen"
"dreamscape"
"acid_wash"
"lomo_inspired"
"retro_futuristic"
"techno_goth"
"film_burn"
"vhs_glitch"
"neon_dreams"
"gothic_romance"
"urban_decay"
"moody_tones"
"classic_hollywood"
"vivid_fashion"
"pastel_cinematic"
"dark_academia"
"electric_city"
"rustic_vignette"
"golden_age"
"film_noir"
"psychedelic_pop"
"retro_sunset"
"heavy_grain"
"analog_fade"
)
# Funksjon for å bruke lineær transformasjon
apply_linear_transform() {
local image_path="$1"
local output_path="$2"
local params="$3"
vips linear "$image_path" "$output_path" $params --uchar
}
# Funksjon for å bruke en generell bildeeffekt
apply_effect() {
local effect="$1"
local output_path="$2"
case $effect in
sharpen)
vips sharpen "$output_path" "$output_path" --sigma 1.5
;;
glow)
vips gamma "$output_path" "$output_path" --exponent 1.4
;;
motionblur)
vips gaussblur "$output_path" "$output_path" --sigma 10
;;
contrast)
vips hist_local "$output_path" "$output_path" --width 5 --height 5
;;
bloom)
vips gaussblur "$output_path" "$output_path" --sigma 15
vips add "$output_path" "$output_path" "$output_path"
;;
edgedetect)
vips sobel "$output_path" "$output_path"
;;
grain)
vips noise "$output_path" "$output_path" --mean 20 --sigma 30
;;
esac
}
# Funksjon for å bruke valgt profil på bildet
apply_preset_profile() {
local image_path="$1"
local output_path="$2"
local profile="$3"
if [[ ! ${preset_profiles[(Ie)$profile]} ]]; then
echo "Ugyldig profil. Tilgjengelige profiler: ${preset_profiles[@]}"
exit 1
fi
echo "Bruker forhåndsinnstilt profil: ${profile}"
case $profile in
vintage_look)
apply_linear_transform "$image_path" "$output_path" "1.2 1.1"
apply_effect "sharpen" "$output_path"
apply_effect "grain" "$output_path"
;;
modern_cinema)
apply_linear_transform "$image_path" "$output_path" "1.3 1.0"
apply_effect "contrast" "$output_path"
apply_effect "bloom" "$output_path"
apply_effect "grain" "$output_path"
;;
noir_cinema)
apply_linear_transform "$image_path" "$output_path" "1.8 1.8"
apply_effect "contrast" "$output_path"
apply_effect "sharpen" "$output_path"
apply_effect "grain" "$output_path"
;;
golden_hour)
apply_linear_transform "$image_path" "$output_path" "0.8 0.8"
apply_effect "contrast" "$output_path"
apply_effect "bloom" "$output_path"
apply_effect "grain" "$output_path"
;;
teal_orange)
apply_linear_transform "$image_path" "$output_path" "1.3 1.0"
apply_effect "contrast" "$output_path"
apply_effect "grain" "$output_path"
;;
bleach_bypass)
apply_linear_transform "$image_path" "$output_path" "1.5 1.5"
apply_effect "contrast" "$output_path"
apply_effect "glow" "$output_path"
apply_effect "grain" "$output_path"
;;
cross_processing)
apply_linear_transform "$image_path" "$output_path" "1.4 0.9"
apply_effect "bloom" "$output_path"
apply_effect "grain" "$output_path"
;;
kodachrome)
apply_linear_transform "$image_path" "$output_path" "1.8 1.2"
apply_effect "sharpen" "$output_path"
apply_effect "contrast" "$output_path"
apply_effect "grain" "$output_path"
;;
film_noir)
apply_linear_transform "$image_path" "$output_path" "1.8 1.8"
apply_effect "contrast" "$output_path"
apply_effect "sharpen" "$output_path"
apply_effect "glow" "$output_path"
apply_effect "motionblur" "$output_path"
apply_effect "grain" "$output_path"
;;
classic_hollywood)
apply_linear_transform "$image_path" "$output_path" "1.2 1.2"
apply_effect "sharpen" "$output_path"
apply_effect "contrast" "$output_path"
apply_effect "bloom" "$output_path"
apply_effect "grain" "$output_path"
;;
low_key)
apply_linear_transform "$image_path" "$output_path" "2.0 1.0"
apply_effect "sharpen" "$output_path"
apply_effect "grain" "$output_path"
;;
high_key)
apply_linear_transform "$image_path" "$output_path" "0.6 0.6"
apply_effect "contrast" "$output_path"
apply_effect "grain" "$output_path"
;;
silver_screen)
apply_linear_transform "$image_path" "$output_path" "1.0 1.0"
apply_effect "contrast" "$output_path"
apply_effect "grain" "$output_path"
;;
day_for_night)
apply_linear_transform "$image_path" "$output_path" "0.5 0.9"
apply_effect "glow" "$output_path"
apply_effect "grain" "$output_path"
;;
golden_age)
apply_linear_transform "$image_path" "$output_path" "1.5 1.5"
apply_effect "contrast" "$output_path"
apply_effect "bloom" "$output_path"
apply_effect "grain" "$output_path"
;;
pastel_cinematic)
apply_linear_transform "$image_path" "$output_path" "0.9 1.1"
apply_effect "contrast" "$output_path"
apply_effect "grain" "$output_path"
;;
dark_academia)
apply_linear_transform "$image_path" "$output_path" "1.3 1.7"
apply_effect "contrast" "$output_path"
apply_effect "grain" "$output_path"
;;
moody_tones)
apply_linear_transform "$image_path" "$output_path" "1.6 1.4"
apply_effect "bloom" "$output_path"
apply_effect "grain" "$output_path"
;;
psychedelic_pop)
apply_linear_transform "$image_path" "$output_path" "1.7 0.9"
apply_effect "edgedetect" "$output_path"
apply_effect "grain" "$output_path"
;;
heavy_grain)
apply_linear_transform "$image_path" "$output_path" "1.0 1.0"
apply_effect "grain" "$output_path"
apply_effect "grain" "$output_path"
;;
analog_fade)
apply_linear_transform "$image_path" "$output_path" "0.9 1.1"
apply_effect "bloom" "$output_path"
apply_effect "grain" "$output_path"
;;
esac
}
# Sjekker antall argumenter og setter fornuftige standardverdier
if [[ $# -lt 1 ]]; then
echo "Bruk: ./postpro.sh <input_bildebane> [<utdata_bildebane>] [<profil>]"
echo "Tilgjengelige profiler: ${preset_profiles[@]}"
exit 1
fi
# Sett standardverdier
image_path="$1"
output_path="${2:-output.png}"
profile="${3:-kodachrome}"
# Kaller funksjonen for å bruke forhåndsinnstilt profil
apply_preset_profile "$image_path" "$output_path" "$profile"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment