10/16/2019

Compress MP4 files


How to compress the MP4 files.

find . -type f -name "*.MP4" -exec bash -c 'FILE="$1"; ffmpeg -i "${FILE}" -s 1280x720 -acodec copy -y "${FILE%.mp4}.shrink.mp4";' _ '{}' \;

Varnish Exemple for CACHE and Optimisation

Varnish Optimisation cache
#
# This is an example VCL file for Varnish.
#
# It does not do anything by default, delegating control to the
# builtin VCL. The builtin VCL is called when there is no explicit
# return statement.
#
# See the VCL chapters in the Users Guide at https://www.varnish-cache.org/docs/
# and https://www.varnish-cache.org/trac/wiki/VCLExamples for more examples.


# Marker to tell the VCL compiler that this VCL has been adapted to the
# new 4.0 format.
vcl 4.0;


# Default backend definition. Set this to point to your content server.
backend default {
.host = "127.0.0.1";
.port = "8080";
}


sub vcl_recv {
# Happens before we check if we have this in cache already.
#
# Typically you clean up the request here, removing cookies you don't need,
# rewriting the request, etc.




# Happens before we check if we have this in cache already.
#
# Typically you clean up the request here, removing cookies you don't need,
# rewriting the request, etc.


# Properly handle different encoding types
if (req.http.Accept-Encoding) {
if (req.url ~ "\.(jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf|woff)$") {
# No point in compressing these
unset req.http.Accept-Encoding;
} elsif (req.http.Accept-Encoding ~ "gzip") {
set req.http.Accept-Encoding = "gzip";
} elsif (req.http.Accept-Encoding ~ "deflate") {
set req.http.Accept-Encoding = "deflate";
} else {
# unknown algorithm (aka crappy browser)
unset req.http.Accept-Encoding;
}
}


# Cache files with these extensions
if (req.url ~ "\.(js|css|jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf|woff)$") {
unset req.http.cookie;
return (hash);
}


# Dont cache anything thats on the blog page or thats a POST request
if (req.url ~ "^/blog" || req.method == "POST") {
return (pass);
}


# This is Laravel specific, we have session-monster which sets a no-session header if we dont really need the set session cookie.
# Check for this and unset the cookies if not required
# Except if its a POST request
if (req.http.X-No-Session ~ "yeah" && req.method != "POST") {
unset req.http.cookie;
}


return (hash);
}


sub vcl_backend_response {
# Happens after we have read the response headers from the backend.
#
# Here you clean the response headers, removing silly Set-Cookie headers
# and other mistakes your backend does.






# set beresp.ttl = 30s;
set beresp.grace = 24h;


if (beresp.ttl < 120s) {
unset beresp.http.cookie;
unset beresp.http.Set-Cookie;
set beresp.ttl = 120s;
unset beresp.http.Cache-Control;
}






}


sub vcl_deliver {
# Happens when we have all the pieces we need, and are about to send the
# response to the client.
#
# You can do accounting or modifying the final object here.
}

Linux Compress PDF batch



#### gs
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf $INPUTFILE

### pdf2ps && ps2pdf
pdf2ps input.pdf output.ps && ps2pdf output.ps output.pdf

### Webservice
http://compress.smallpdf.com/de
For linux
#!/bin/sh
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/default -dNOPAUSE -dQUIET -dBATCH -dDetectDuplicateImages -dCompressFonts=true -r150 -sOutputFile="compress_$@" "$@"
 ./compresspdf.sh file.pdf 
find -type f -name "*.pdf" -exec ./compresspdf.sh {} \;
#!/bin/sh
INPUT=$1; shift
OUTPUT=$1; shift
GS_BIN=/usr/bin/gs
QFACTOR="0.40"

# Image Compression Quality
#
# Quality HSamples VSamples QFactor
# Minimum [2 1 1 2] [2 1 1 2] 2.40
# Low     [2 1 1 2] [2 1 1 2] 1.30
# Medium  [2 1 1 2] [2 1 1 2] 0.76
# High    [1 1 1 1] [1 1 1 1] 0.40
# Maximum [1 1 1 1] [1 1 1 1] 0.15 

${GS_BIN} -dBATCH -dSAFER -DNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=${OUTPUT} -c "<< /ColorImageDict << /QFactor ${QFACTOR} /Blend 1 /HSample [1 1 1 1] /VSample [1 1 1 1] >> >> setdistillerparams" -f ${INPUT}

For windows
echo off
:: PDF to PCL Converter. Needs Ghostscript locally, and installed here: "C:\Program Files\gs\gs9.02\bin\gswin32c.exe"
:: Other versions of GS will work, but the script will have to be updated.
:: Users can enter the breakpoint for the PCL files. If none is provided, 100 is used.
cls
echo This program will take all the PDF files in the current directory
echo and group them into PCL files. If you ran
echo this from the command line, you could enter the breakpoint for
echo number of PDF files per PCL. If left blank or not entered, the
echo program defaults to 100.
echo.
echo If you want to continue, hit any key and please wait for the
echo program to complete processing (could take a while).
echo If you want to stop now, hit CTRL-C and exit out of the batch.
pause

setlocal enabledelayedexpansion
set INC=%1
if "%1%" == "" set INC=100
SET GSS=
SET CTR=0
SET FL=1

for %%i in (*.pdf) DO (
SET GSS=!GSS! "%%i"
SET /a CTR+=1
echo !CTR! COUNTER !FL! OUTPUTFILE NUMBER
if !CTR! == %INC% (

"C:\Program Files\gs\gs9.02\bin\gswin32c.exe" -dNOPAUSE -dBATCH -sDEVICE=laserjet -sOutputFile=File_!FL!.pcl !GSS!
echo "C:\Program Files\gs\gs9.02\bin\gswin32c.exe" -dNOPAUSE -dBATCH -sDEVICE=laserjet -sOutputFile=File_!FL!.pcl !GSS!
set /a FL+=1
echo !FL! FL
set CTR=0
set GSS=

)

)
if NOT !CTR! == 0 (
echo LAST PROCESS
"C:\Program Files\gs\gs9.02\bin\gswin32c.exe" -dNOPAUSE -dBATCH -sDEVICE=laserjet -sOutputFile=File_!FL!.pcl !GSS!
)


endlocal
echo Complete.
echo on

10/15/2019

resize images in Linux



Reduce images files png or jpg jpeg in subdirectories

find -type f -name "*.jpeg" -exec jpegoptim --strip-all {} \;


optipng *.png

find -type f -name "*.png" -exec optipng {} \;