C'est pour cette raison que j'avais écrit un script de wrapper interactif pour les ordinateurs de bureau Unix. Après un an d'utilisation, je suis ravi de le partager ici!
Fait avec byzanz
, gifsicle
, xdotool
et le script est écrit dans php
.
Exemple de sortie:
[1020px, largeur gif non redimensionnée 1020px, 70 secondes, 50 couleurs, 65Ko ]
Il fournit de bons gifs compressés et constitue une bonne vitrine pour cette question.
Ceci est une base assez simple, prête à être piratée par vous.
Fonctionnalités : Enregistrement GIF aux positions de la souris ou en plein écran, redimensionnement, compression, compression des couleurs, inversion / fusion, téléchargement giphy.com.
Pour commencer un enregistrement gif de 10 secondes: gif 10
Pour enregistrer plusieurs fois avec les mêmes paramètres: gif !
Pour démarrer un enregistrement gif plein écran de 5 secondes: gif 5 --fullscreen
Le script court, s'enregistre agréablement:
[ 45 secondes, largeur 645 pixels, couleurs pleines, 976 Ko ]
Script complet de 5 Ko:
#!/usr/bin/php
<?php
#> php xdotool byzanz gifsicle curl
#@ https://webdev23.github.io/gif/gif
echo "Usage: ./gif [time in seconds|!] [--fullscreen|-f]\n";
echo "--------------------------------------------------\n";
echo "Gif recorder tool\n";
echo "gif ! to call back last settings\n";
echo "Please move your mouse at the top left corner point\n";
echo "of the wanted gif area. Then press enter.\n";
echo "\n";
#~ Nico KraZhtest | 05/2017 | https://github.com/webdev23/gif
#~ Create fluid GIF's fastly
#~ You can set the gif record time as argument: ./gif 10
#~ Default record time is 1 seconde, or set it now:
$recordTime = 1;
#~ ----------------
$t = @$argv[1];
$x1;$y1;$x2;$y2;$gw;$gh;$defc;$rw;
if (!isset($argv[1]) || @$argv[1] === "!") {
$t = $recordTime;
}
if (@$argv[1] === "!") {
$pos = file_get_contents("./.config/gif/pos");
$pos = explode("\n", $pos);
$x1 = $pos[0];
$y1 = $pos[1];
$x2 = $pos[2];
$y2 = $pos[3];
$gw = $pos[4];
$gh = $pos[5];
$t = $pos[6];
@$GLOBALS['defc'] = $pos[7];
@$GLOBALS['$rw'] = $pos[8];
#~ echo $x1." ".$y1." ".$x2." ".$y2." ".$gw." ".$gh." ".$t." ".$defc." ".@$rw;
}
else if (@$argv[2] === "fullscreen" || @$argv[2] === "--fullscreen" || @$argv[2] === "-f" || @$argv[2] === "f") {
echo "############\nStarting fullscreen record\n";
$fs = system("xdpyinfo | grep 'dimensions:'");
echo "\n";
$fs = explode(" ",$fs);
echo $fs[1];
$fs = explode(" ",$fs[1]);
echo $fs[0];
$fs = explode("x",$fs[0]);
echo $fs[0]."\n";
echo $fs[1];
$x1 = "0";
$y1 = "0";
$x2 = "fs";
$y2 = "fs";
$gw = $fs[0];
$gh = $fs[1];
$t = $argv[1];
system("mkdir -p ./.config/gif/");
system("cd ./.config/gif/ && \
echo '$x1\n$y1\n$x2\n$y2\n$gw\n$gh\n$t\n\n\n\n' > pos");
}
else {
$stdin = fopen('php://stdin', 'r');
$response = rtrim(fgets(STDIN));
$p1 = system("xdotool getmouselocation");
$pos1 = explode(" ",$p1);
$x1 = $pos1[0];
$x1 = explode(":",$x1);
$x1 = $x1[1];
echo "X1: ".$x1;
$y1 = $pos1[1];
$y1 = explode(":",$y1);
$y1 = $y1[1];
echo " Y1: ".$y1;
echo "\nNow move your mousse at the bottom right corner.\nThen enter\n";
$stdin = fopen('php://stdin', 'r');
$response = rtrim(fgets(STDIN));
$p2 = system("xdotool getmouselocation");
$pos2 = explode(" ",$p2);
$x2 = $pos2[0];
$x2 = explode(":",$x2);
$x2 = $x2[1];
echo "X2: ".$x2;
$y2 = $pos2[1];
$y2 = explode(":",$y2);
$y2 = $y2[1];
echo " Y2: ".$y2;
$gw = ($x2 - $x1);
echo "\nGif width: ".$gw;
$gh = ($y2 - $y1);
echo "\nGif height: ".$gh;
echo "\n".$x1." ".$y1." ".$x2." ".$y2." ".$gw." ".$gh." ".$t."\n";
system("mkdir -p ./.config/gif/");
system("cd ./.config/gif/ && \
echo '$x1\n$y1\n$x2\n$y2\n$gw\n$gh\n$t\n\n\n\n' > pos");
}
$unix = date_timestamp_get(date_create());
echo "\n".$unix." | Starting ".$t."s gif record\n";
@system("byzanz-record \
-v \
--duration=$t \
--x=$x1 \
--y=$y1 \
--width=$gw \
--height=$gh \
~/Pictures/gif$unix.gif");
$named = "gif".$unix;
echo "Saved as ~/Pictures/".$named.".gif\n";
echo "\nOptimize | How many colors to keep? (default 100, max 256) \n";
if (@$argv[1] === "!"){
$pos = file_get_contents("./.config/gif/pos");
$pos = explode("\n", $pos);
$defc = $pos[7];
}
if (!isset($defc)){
$defc = readline("Colors: ");
}
if (empty($defc)){
$defc = "100";
}
echo "\nKeeping ".$defc." colors\n";
system("gifsicle --verbose -i ~/Pictures/$named.gif -O5 --colors=$defc -o ~/Pictures/$named\_reduced.gif");
echo "\nOptimize | Resize width in pixels (default 360px) \n";
if (@$argv[1] === "!"){
$pos = file_get_contents("./.config/gif/pos");
$pos = explode("\n", $pos);
$rw = $pos[8];
}
if (!isset($rw)){
$rw = readline("Width : ");
}
if (empty($rw)){
$rw = "360";
}
echo "\nResized by ".$rw." pixels width\n";
@system("gifsicle --verbose -i ~/Pictures/$named\_reduced.gif --resize-width $rw -o ~/Pictures/".$named."_optimized.gif");
$opt = "~/Pictures/".$named."_optimized.gif";
usleep(5000000);
echo "\nSpecial | Reverse and merge?\n";
system("xdg-open ~/Pictures/".$named."_optimized.gif > /dev/null");
if (@$argv[1] === "!"){
$pos = file_get_contents("./.config/gif/pos");
$pos = explode("\n", $pos);
$rev = $pos[9];
}
if (!isset($rev)){
$stdin = fopen('php://stdin', 'r');
$rev = rtrim(fgets(STDIN));
$rev = "1";
}
if (!isset($rev)){
$rev = "0";
}
@system("cd ./.config/gif/ && sed -i '8s/.*/$defc/' pos");
@system("cd ./.config/gif/ && sed -i '9s/.*/$rw/' pos");
@system("cd ./.config/gif/ && sed -i '10s/.*/$rev/' pos");
if ($rev === "1"){
@system("gifsicle \
-i ~/Pictures/$named\_reduced.gif \
'#-2-1' \
-o ~/Pictures/".$named."_reversed.gif");
$inv = "~/Pictures/".$named."_reversed.gif";
usleep(400000);
@system("gifsicle \
-i ~/Pictures/$named\_reduced.gif \
--append $inv \
--resize-width $rw \
-o ~/Pictures/".$named."_merged.gif");
usleep(3000000);
system("xdg-open ~/Pictures/".$named."_merged.gif > /dev/null");
}
echo "\n####################";
echo "\nUpload to giphy.com?\n";
$stdin = fopen('php://stdin', 'r');
$response = rtrim(fgets(STDIN));
$m = "~/Pictures/".$named."_merged.gif";
$f = system("du -h $m");
$f = explode(" ",$f);
$f = $f[1];
$www = system('curl \
--progress-bar \
-v \
-F "file=@'.$f.'" \
-F "api_key=dc6zaTOxFJmzC" \
"http://upload.giphy.com/v1/gifs"');
$www = json_decode($www);
echo "\n\nhttps://i.giphy.com/".$www->data->id.".gif\n";
echo "\nThanks YOU!\n";
Possibilité d'inverser / fusionner pour créer des contenus artistiques.
Original (435kb)
Renversé, fusionné: (826kb)
Pour installer, en utilisant phi :
php <(curl https://webdev23.github.io/phi/phi) install https://webdev23.github.io/gif/gif
Plein écran:
[1920 * 1080px, gif 400px, 50 secondes , 100 couleurs, 2Mo ]
Source, avec quelques explications supplémentaires et des mises à jour potentielles:
https://github.com/webdev23/gif