#!/usr/bin/awk -f # jpg2eps -- Heiko Purnhagen (purnhage@tnt.uni-hannover.de) # HP 20020903 # HP 20030807 fixed "xxx BINARY Bytes" bug # # Usage: # jpg2eps image.jpg > image.eps # (requires ImageMagick 5.4.4) # # Background: # JPEG-to-EPS conversion by # convert -compress JPEG -quality 75 image.jpg eps2:image.eps # always transcodes the original JPEG image - this script just "wraps" # the original JPEG file # # Links: # http://www.tnt.uni-hannover.de/~purnhage/software/jpg2eps # http://www.tnt.uni-hannover.de/~purnhage/software/epstopdf-fixjpg.c # http://www.imagemagick.org/www/identify.html BEGIN { if (ARGC!=2) { print "jpg2eps (HP20020903)" > "/dev/stderr" print "usage: jpg2eps image.jpg > image.eps" > "/dev/stderr" exit -1 } "date" | getline datetime "identify -format \"%w %h\" " ARGV[1] | getline jpgxy "wc -c "ARGV[1] | getline jpglen isgray = (system("identify -verbose " ARGV[1] " | grep \"Type: true color\" > /dev/null")) print "%!PS-Adobe-3.0 EPSF-3.0\n\ %%Creator: (jpg2eps)\n\ %%Title: (" ARGV[1] ")\n\ %%CreationDate: (" datetime ")\n\ %%BoundingBox: 0 0 " jpgxy print "%%LanguageLevel: 2\n\ %%Pages: 1\n\ %%EndComments\n\ \n\ %%BeginDefaults\n\ %%EndDefaults\n\ \n\ %%BeginProlog\n\ %\n\ % Display a color image. The image is displayed in color on\n\ % Postscript viewers or printers that support color, otherwise\n\ % it is displayed as grayscale.\n\ %\n\ /DirectClassImage\n\ {\n\ %\n\ % Display a DirectClass image.\n\ %\n\ colorspace 0 eq\n\ {\n\ /DeviceRGB setcolorspace\n\ <<\n\ /ImageType 1\n\ /Width columns\n\ /Height rows\n\ /BitsPerComponent 8\n\ /Decode [0 1 0 1 0 1]\n\ /ImageMatrix [columns 0 0 rows neg 0 rows]\n\ compression 0 gt\n\ { /DataSource pixel_stream /DCTDecode filter }\n\ { /DataSource pixel_stream /DCTDecode filter } ifelse\n\ >> image\n\ }\n\ {\n\ /DeviceCMYK setcolorspace\n\ <<\n\ /ImageType 1\n\ /Width columns\n\ /Height rows\n\ /BitsPerComponent 8\n\ /Decode [0 1 0 1 0 1 0 1]\n\ /ImageMatrix [columns 0 0 rows neg 0 rows]\n\ compression 0 gt\n\ { /DataSource pixel_stream /DCTDecode filter }\n\ { /DataSource pixel_stream /DCTDecode filter } ifelse\n\ >> image\n\ } ifelse\n\ } bind def\n\ \n\ /PseudoClassImage\n\ {\n\ %\n\ % Display a PseudoClass image.\n\ %\n\ % Parameters:\n\ % colors: number of colors in the colormap.\n\ %\n\ currentfile buffer readline pop\n\ token pop /colors exch def pop\n\ colors 0 eq\n\ {\n\ %\n\ % Image is grayscale.\n\ %\n\ currentfile buffer readline pop\n\ token pop /bits exch def pop\n\ /DeviceGray setcolorspace\n\ <<\n\ /ImageType 1\n\ /Width columns\n\ /Height rows\n\ /BitsPerComponent bits\n\ /Decode [0 1]\n\ /ImageMatrix [columns 0 0 rows neg 0 rows]\n\ compression 0 gt\n\ { /DataSource pixel_stream /DCTDecode filter }\n\ {\n\ /DataSource pixel_stream /DCTDecode filter\n\ <<\n\ /K -1\n\ /Columns columns\n\ /Rows rows\n\ >> /CCITTFaxDecode filter\n\ } ifelse\n\ >> image\n\ }\n\ {\n\ %\n\ % Parameters:\n\ % colormap: red, green, blue color packets.\n\ %\n\ /colormap colors 3 mul string def\n\ currentfile colormap readhexstring pop pop\n\ [ /Indexed /DeviceRGB colors 1 sub colormap ] setcolorspace\n\ <<\n\ /ImageType 1\n\ /Width columns\n\ /Height rows\n\ /BitsPerComponent 8\n\ /Decode [0 255]\n\ /ImageMatrix [columns 0 0 rows neg 0 rows]\n\ compression 0 gt\n\ { /DataSource pixel_stream /DCTDecode filter }\n\ { /DataSource pixel_stream /DCTDecode filter } ifelse\n\ >> image\n\ } ifelse\n\ } bind def\n\ \n\ /DisplayImage\n\ {\n\ %\n\ % Display a DirectClass or PseudoClass image.\n\ %\n\ % Parameters:\n\ % x & y translation.\n\ % x & y scale.\n\ % label pointsize.\n\ % image label.\n\ % image columns & rows.\n\ % class: 0-DirectClass or 1-PseudoClass.\n\ % colorspace: 0-RGB or 1-CMYK.\n\ % compression: 0-RunlengthEncodedCompression or 1-NoCompression.\n\ % hex color packets.\n\ %\n\ gsave\n\ /buffer 512 string def\n\ /pixel_stream currentfile def\n\ \n\ currentfile buffer readline pop\n\ token pop /x exch def\n\ token pop /y exch def pop\n\ x y translate\n\ currentfile buffer readline pop\n\ token pop /x exch def\n\ token pop /y exch def pop\n\ currentfile buffer readline pop\n\ token pop /pointsize exch def pop\n\ /Helvetica findfont pointsize scalefont setfont\n\ x y scale\n\ currentfile buffer readline pop\n\ token pop /columns exch def\n\ token pop /rows exch def pop\n\ currentfile buffer readline pop\n\ token pop /class exch def pop\n\ currentfile buffer readline pop\n\ token pop /colorspace exch def pop\n\ currentfile buffer readline pop\n\ token pop /compression exch def pop\n\ class 0 gt { PseudoClassImage } { DirectClassImage } ifelse\n\ grestore\n\ } bind def\n\ %%EndProlog\n\ %%Page: 1 1" if (isgray) { print "%%PageBoundingBox: 0 0 " jpgxy "\n\ userdict begin" printf "%%%%BeginData: %10d BINARY Bytes\n",39+2*length(jpgxy)+jpglen print "DisplayImage\n\ 0 0\n\ " jpgxy "\n\ 12.000000\n\ " jpgxy "\n\ 1\n\ 0\n\ 1\n\ 0\n\ 8" } else { print "%%PageBoundingBox: 0 0 " jpgxy "\n\ userdict begin" printf "%%%%BeginData: %10d BINARY Bytes\n",35+2*length(jpgxy)+jpglen print "DisplayImage\n\ 0 0\n\ " jpgxy "\n\ 12.000000\n\ " jpgxy "\n\ 0\n\ 0\n\ 0" } system("cat " ARGV[1]) print "\n\ %%EndData\n\ end\n\ %%PageTrailer\n\ %%Trailer\n\ %%BoundingBox: 0 0 " jpgxy "\n\ %%EOF" }