Script of the picture

xiaoxiao2021-03-06  24

Pike wrote, some scripts that operate on the picture, can use it when you use it, you can use it.

/ / The program is tested into the picture of .jpg, the scaling of the picture, INT Main (int Num, array (string) args) {if (num == 2) {string image = args [1]; write (image "/ n "); Mixed err = catch {WRITE (" Image Convert Test! / N "); string t_str = image.load_file (image); Object O; IF (Search (Image,")> 0 || Search (Image, "," ")> 0 || Search (Image,". Bmp.png ")> 0) {Write (" is the transferred image, no longer handling | " image " / N "); RETURN 1;} IF (search (image,")> 0) o = image.jpeg.decode (t_str); Else IF (Search (Image, ")> 0) {o = Image.png.decode (t_str);} else o = image.jpeg.decode (t_str);

INT x = O-> xsize (); int y = O-> ysize (); write ("x:" "Y:" y "/ n"); if (x> 110 && o! = 0) { Float XX = (float) x; float xx_r = 110.0 / xx; Write ("scale rate" xx_r "/ n"); o = O-> scale (xx_r); string ret = ""; if (search (Image) , ". JPG")> 0) RET = Image.jpeg.Encode (O); Else IF (Search (Image, ")> 0) RET = Image.png.Encode (O); Else Ret = Image .Jpeg.encode (o);

Stdio.write_file (image, re);}; if (err) {WRITE ("internal error / n");}}}} else {write ("Parameter Error");} Return 1;} The following program is Format images are converted into a PNG format

Format_Decode.pike

INT Main (int Num, array (string) args {if (num == 2) {string image = args [1]; // Write (image "/ n"); // mixed err = catch {Write (" *********************** Image Decode Test Begin! *************** / N "); String t_str = image.load_file (image); Object O; //if (Search (Simage, "jpg.png"?)) | | |ar (image ,".gif.png"?) 0|||| , ". bmp.png")> 0 || Search (Image, "PNG")> 0 || Search (Image, ". PNG")> 0) IF (Search (Image, ")> 0 || Search (Image, "")> 0) {Write ("is the transferred image, no longer processed |" image "/ n"); Return 1;} if (Search (Image). JPG ")> 0 || Search (image,". jpg ")> 0) {Write (" Yes .jpg .jpg | " Image " / n "); o = image.jpeg.decode (t_str);} ELSE IF (Search, ",", ",". GIF ")> 0) {Write (" Yes .gif .gif | " Image " / n "); o = Image .Gif.decode (t_str);} else IF (search (image, ")> 0 || Search (Image,". BMP ")> 0) {WRITE ("Yes .bmp .bmp |" Image "/ n"); o = image.bmp.decode (t_str);} if (o! = 0) {Write ("Save as ... / N "); string ret = image.png.encode (o); string decode_img = image [0..sizeof (image) -5]; stdio.write_file (decode_img ". PNG ", RET); // Delete the original JPG or other format of the original image of String CMD = "RM" Image; Process.System (CMD);

} WRITE ("********************************************** / n ");} returnit 1;}

script:

#! / bin / sh

Export path = $ path: / usr / local / bin: / usr / bin: / usr / local / sbin # Backup original image information / bin / cp -fr / home / xxx / data / * / home / xxx / data -BAK

DIR = .curfiles = $ (Find / Home / XXX / DATA /)

# 转 转 图片 图片 图 为 $ curfilesfor file in $ curfilesdo if [-f $ file] THEN / USR / local / bin / pike /Home/xxx/bin/format_decode.pike $ file echo $ file fidone

转载请注明原文地址:https://www.9cbs.com/read-65573.html

New Post(0)