HTML5¼¼Êõ

ŨËõµÄ²ÅÊǾ«»ª£ºÇ³ÎöGIF¸ñʽͼƬµÄ´æ´¢ºÍѹËõ - ÌÚѶÔƼ¼ÊõÉçÇø(4)

×ÖºÅ+ ×÷ÕߣºH5Ö®¼Ò À´Ô´£ºH5Ö®¼Ò 2017-04-07 15:08 ÎÒÒªÆÀÂÛ( )

ÌáÈ¡³öÿһ֡µÄdelayÐÅÏ¢£¬Ò²¿ÉÒÔͨ¹ý¹¤¾ßÌṩµÄÃüÁîÀ´ÌáÈ £ gm identify -verbose source .gif gifsicle -I source .gif ÔÚʵ¼ÊÓ¦ÓÃÖУ¬³éÖ¡µÄ¼ä¸ôgapÊǸù¾Ý×ÜÖ¡ÊýframeÇó³öµÄ frame8 gap=19frame20 gap=221frame3

ÌáÈ¡³öÿһ֡µÄdelayÐÅÏ¢£¬Ò²¿ÉÒÔͨ¹ý¹¤¾ßÌṩµÄÃüÁîÀ´ÌáÈ¡¡£

gm identify -verbose source.gif gifsicle -I source.gif

ÔÚʵ¼ÊÓ¦ÓÃÖУ¬³éÖ¡µÄ¼ä¸ôgapÊǸù¾Ý×ÜÖ¡ÊýframeÇó³öµÄ

frame<8 gap=1 9<frame<20 gap=2 21<frame<30 gap=3 31<frame<40 gap=4 frame>40 gap=5

delayÖµµÄ¼ÆË㻹×öÁ˹éÒ»»¯´¦Àí£¬Èç¹ûÐÂÉú³ÉËõÂÔͼµÄÖ¡¼ä¸ôƽ¾ùÖµ´óÓÚ200ms£¬Ôòͳһ¼ÓËÙµ½¾ùÖµ200ms£¬Í¬Ê±±£³ÖÔ­ÓнÚ×࣬ÕâÑù¿ÉÒÔ±ÜÃ⼫¶ËÇé¿öÏ£¬ËõÂÔͼ¹ýÓÚ³Ù»º¡£

¾ßÌåʵÏÖ

±¾ÎĽéÉܵÄËã·¨Ö÷ÒªÓ¦ÓÃÓÚÊÖQÈÈͼ¹¦Äܵĺǫ́¹ÜÀíϵͳ£¬Ê¹ÓÃNodejs±àд¡£
ImageMagickÊÇÒ»¸ö½ÏΪ³£ÓõÄͼÏñ´¦Àí¹¤¾ß£¬³ýÁËgif»¹¿ÉÒÔ´¦Àí¸÷ÀàͼÏñÎļþ£¬ÓÐnode·â×°µÄ°æ±¾¿ÉÒÔʹÓá£
gifsicleÖ»ÓпÉÖ´Ðа汾£¬ÔÚ·þÎñÆ÷ÉÏÖØбàÒëÔ´Âëºó£¬²ÉÓÃspawnµ÷Æð×Ó½ø³ÌµÄ·½Ê½ÊµÏÖ¡£

ImageMagick¶ÔÓÚͼƬÐÅÏ¢µÄ½âÎö½ÏΪ·½±ã£¬¿ÉÒÔÖ±½ÓµÃµ½½á¹¹»¯ÐÅÏ¢¡£
gifsicleÖ§³ÖÃüÁî¹ÜµÀ¼¶Áª£¬´¦ÀíͼƬËٶȽϿ졣
ʵ¼ÊÉú²ú¹ý³ÌÖУ¬Í¬Ê±²ÉÓÃÁËÁ½¸ö¹¤¾ß¡£

const {spawn} = require('child_process'); const image = gm("src2/"+file) image.identify((err, val) => { if(!val.Scene){ console.log(file+" has err£º"+err) return } let frames_count = val.Scene[0].replace(/\d* of /, '') * 1 let gap = countGap(frames_count) let delayList = []; let totaldelay = 0 if(val.Delay!=undefined){ let i for (i = 0; i < val.Delay.length; i ++) { delayList[i] = val.Delay[i].replace(/x\d*/, '') * 1 totaldelay+=delayList[i] } for (; i < val.Scene.length; i ++) { delayList[i] = 8 totaldelay+=delayList[i] } }else{ for (let i = 0; i < val.Scene.length; i ++) { delayList[i] = 8 totaldelay+=delayList[i] } } let totalFrame = parseInt(frames_count/gap) //ÅжÏÊÇ·ñËٶȹýÂý£¬ÐèÒª½øÐйéÒ»¼ÓËÙ´¦Àí if(totaldelay/totalFrame>20){ let scale =(totalFrame*1.0*20)/totaldelay for (let i = 0; i < delayList.length; i ++) { delayList[i] = parseInt(delayList[i] * scale) } } let params=[] params.push("--colors=255") params.push("--unoptimize") params.push("src2/"+file) let tempdelay = delayList[0] for (let i = 1; i < frames_count; i ++) { if(i%gap==0){ params.push("-d"+tempdelay) params.push("#"+(i-gap)) tempdelay=0 } tempdelay += delayList[i] } params.push("--optimize=3") params.push("-o") params.push("src2/"+file+"gap-keepdelay.gif") spawn("gifsicle", params, { stdio: 'inherit' }) })

²âÊÔʱ£¬²ÉÓøÃËã·¨Ëæ»úÑ¡Ôñ50ÕÅgifͼ½øÐÐѹËõ£¬Ô­³ß´ç15.5M±»Ñ¹Ëõµ½6.0M£¬Ñ¹Ëõ±È38%£¬²»¹ýÓÉÓÚ¸ÃËã·¨µÄѹËõ±ÈÂʺ;ßÌåͼƬÖÊÁ¿¡¢Ö¡Êý¡¢Í¼ÏñÌØÕ÷Óйأ¬²âÊÔÊý¾Ý½ö¹©²Î¿¼¡£

±¾Îĵ½ÕâÀï¾Í½áÊøÁË£¬Ô­À´¿´ËƼòµ¥µÄ±íÇé°ü£¬Ò²Óв»ÉÙÎÄÕ¿É×ö¡£

лл¹Û¿´£¬Ï£ÍûÎÄÖнéÉܵÄ֪ʶºÍÑо¿·½·¨¶ÔÄãÓÐËùÆô·¢¡£

 

Ïà¹ØÍƼö

iOS¸ßÐÔÄÜͼƬ¼Ü¹¹ÓëÉè¼Æ
¹È¸è¿ªÔ´Í¼Æ¬Ñ¹ËõËã·¨Guetzliʵ²âÌåÑ鱨¸æ
¹ØÓÚAndroidͼƬ×ÊÔ´ÊÝÉíµÄÆæ˼ÃîÏë

 

´ËÎÄÒÑÓÉ×÷ÕßÊÚȨÌÚѶÔƼ¼ÊõÉçÇø·¢²¼£¬×ªÔØÇë×¢Ã÷ÎÄÕ³ö´¦£¬»ñÈ¡¸ü¶àÔƼÆËã¼¼Êõ¸É»õ£¬¿ÉÇëÇ°ÍùÌÚѶÔƼ¼ÊõÉçÇø

Ô­ÎÄÁ´½Ó£ºhttps://www.qcloud.com/community/article/946621001490345387

»¶Ó­´ó¼Ò¹Ø×¢ÌÚѶÔƼ¼ÊõÉçÇø-²©¿ÍÔ°¹Ù·½Ö÷Ò³£¬ÎÒÃǽ«³ÖÐøÔÚ²©¿Í԰Ϊ´ó¼ÒÍƼö¼¼Êõ¾«Æ·ÎÄÕÂŶ~

¡¡

1.±¾Õ¾×ñÑ­ÐÐÒµ¹æ·¶£¬ÈκÎתÔصĸå¼þ¶¼»áÃ÷È·±ê×¢×÷ÕߺÍÀ´Ô´£»2.±¾Õ¾µÄÔ­´´ÎÄÕ£¬ÇëתÔØʱÎñ±Ø×¢Ã÷ÎÄÕÂ×÷ÕߺÍÀ´Ô´£¬²»×ðÖØÔ­´´µÄÐÐΪÎÒÃǽ«×·¾¿ÔðÈΣ»3.×÷ÕßͶ¸å¿ÉÄܻᾭÎÒÃDZ༭Ð޸Ļò²¹³ä¡£

Ïà¹ØÎÄÕÂ
  • ÄãÊ×ÏÈÊÇÒ»¸öÈË£¬È»ºóÄã²ÅÊdzÌÐòÔ±¡£ - ×óäìÁú

    ÄãÊ×ÏÈÊÇÒ»¸öÈË£¬È»ºóÄã²ÅÊdzÌÐòÔ±¡£ - ×óäìÁú

    2017-03-22 14:00

  • ³ÌÐòÔ³¿´Ð¡Ëµ»¹ÒªÈ¥ÕÒTXT£¿×Ô¼º¶¯ÊÖÅÀÒ»¸öTXT²ÅÊÇÕýÈ·µÄ´ò¿ª·½Ê½ - JangoJing

    ³ÌÐòÔ³¿´Ð¡Ëµ»¹ÒªÈ¥ÕÒTXT£¿×Ô¼º¶¯ÊÖÅÀÒ»¸öTXT²ÅÊÇÕýÈ·µÄ´ò¿ª·½Ê½ - J

    2016-06-29 17:00

  • ZyngaµÂ¹úÖ÷¹Ü£ºHTML5²ÅÊÇÓÎÏ·ÐÐҵδÀ´_HTML5ÖÐÎÄÍø

    ZyngaµÂ¹úÖ÷¹Ü£ºHTML5²ÅÊÇÓÎÏ·ÐÐҵδÀ´_HTML5ÖÐÎÄÍø

    2014-11-17 18:29

ÍøÓѵãÆÀ