aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/rewritejpeg
blob: 21822c72313042da2c1ac36c2f373e8d0a6d1257 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/bash
# -*- Mode: shell-script -*-
# Copyright (C) 2002 by Chmouel Boudjnah <chmouel@mandrakesoft.com>
# Redistribution of this file is permitted under the terms of the GNU 
# Public License (GPL)
#
# Take a Jpeg and reconvert it via ppm-tools to make sure is
# compatible for boot logo
#
# Modified by Olivier Blin on October 30, 2003.
# grayscale jpeg support.
# it's perhaps better to use "convert -type TrueColor"
#
# $Id$

files="$@"

[[ -z $files ]] && {
    echo "I need jpeg files argument"
    exit 1
}

for file in $files;do
    [[ $file != *.jpg ]] && { 
	echo "$file is not a jpeg"
	continue;
    }
    tmp_ppm=${file/.jpg/.ppm}
    output=`jpegtopnm $file 2>&1 > $tmp_ppm`
    echo $output
    if [[ $output == *PGM* ]]; then
        tmp_pgm=${file/.jpg/.pgm}
        mv $tmp_ppm $tmp_pgm
        echo "(converting PGM file into PPM file)"
        pgmtoppm grey $tmp_pgm > $tmp_ppm
        rm -f $tmp_pgm
    fi 
    ppmtojpeg $tmp_ppm > $file
    rm -f $tmp_ppm
done