Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                背景<br /><input type="file"  onchange="yomi(0)" /><br />
透過素材<br /><input type="file"  onchange="yomi(1)" /><br />

<div id="moto"> </div>

wid
<input type="text" id="wid" value="500" size=3 />
hei
<input type="text" id="hei" value="300" size=3 />
   <input type="button" value="サイズ変更" onclick="init()"/>
<br />

<canvas></canvas>

<br /><input type="button" onclick="ch()" id="stb" value="動作チェック" />
<br />

<textarea id="bun" cols="50" rows="10">
どこかがじょじょに変化していきます
わかるかな~?
</textarea>

<br />
フレーム数
<input type="text" id="maisuu" value="30" size=3 />
文字サイズ
<input type="text" id="futosa" value="30" size=3 />
<input type="checkbox" id="gya" />逆

<br />

<input type="button" onclick="gifka()" value="GIF作成" />↓
<div id="mega"></div>
<br />

<br />
<img></img>
<br />
<input type="button" onclick="tome()"  id="tome" value="×" />
<br />

<span>
    <canvas style="position:absolute;top:0;width:100%;height:100%" ></canvas>
    <div class="a">
        Please wait
        <br />
        <br />
        <div style="width:300px;height:10px;background-color:#bbbbbb;">
            <div id="sin" style="width:2px;height:10px;background-color:#ffeeaa;"></div>
        </div>
        <div id="tyoku" style="font-size:25px;"></div>
        <br />
        <input type="button" onclick="isrend=0;"  value="cancel" />
    </div>
</span>

<br /><br /><br />
~使い方~
<br /><br />
・画像を2つ読み込みます
<br /><br />
・ポイント(四角)をドラッグして調整します
<br /> 赤:透過素材の位置
<br /> 青:透過素材の大きさと角度
<br /><br />
・GIF作成ボタンを押します
<br /><br />
・できたGIFを右クリックで保存します
<br /><br />
・ついでに製作者のアカウントをフォローします<br />
<a href="https://twitter.com/jagarikin" target="blank">
https://twitter.com/jagarikin</a>

<br /><br />
※IE非推奨
<br /><br />
              
            
!

CSS

              
                div.a {
    text-align:center;
    font-size:25px;
    color: #000000;
    background-color: #aaffee;
    position: absolute;
    height:140;
    width:300;
    top:50%;
    left:50%;
    margin-top: -70px; margin-left: -150px;
}
              
            
!

JS

              
                var canvas,ctx,count,ho,canvas2,ctx2,gmax,timer,isstart,futosa,zah,wtime,
    nowbit,nowpin,kari,tan8,bgr,mousex,mousey,nowpo,poi,tim,
    sax,say,isrend,mae,isma,posize,imas;

canvas = document.getElementsByTagName('canvas')[0];
ctx = canvas.getContext('2d');
canvas2 = document.getElementsByTagName('canvas')[1];
ctx2 = canvas2.getContext('2d');
ctx2.fillStyle="rgba(0,0,0,0.4)";
ctx2.fillRect(0,0,canvas2.width,canvas2.height);

document.getElementsByTagName('span')[0].style.visibility="hidden";
document.getElementById("tome").style.visibility="hidden";
document.body.onselectstart=function(){return false;};
window.onscroll =function(){
    var a=document.documentElement.scrollTop || document.body.scrollTop;
    canvas2.style.top=a+"px";
};

mousex=mousey=nowpo=0;
if (navigator.userAgent.indexOf('iPhone') > 0 || 
    navigator.userAgent.indexOf('iPad') > 0 || 
    navigator.userAgent.indexOf('iPod') > 0 || navigator.userAgent.indexOf('Android') > 0) {
        canvas.addEventListener('touchstart', mdn);
        canvas.addEventListener('touchmove', mmv);
        canvas.addEventListener('touchend', function(){nowpo=0;});
        document.body.removeEventListener('touchmove', 0, false);
        posize=16;
        isma=1;
    }else{
        document.onmouseup=function(){nowpo=0;};
        canvas.addEventListener('mousemove', mmv);
        canvas.addEventListener('mousedown', mdn); 
        posize=5;
    }

wtime=3;
imas=[];
init();


function init(){
    var a,b,c;
    count=0;
    canvas.width=namnam("wid",3,5000,400);
    canvas.height=namnam("hei",3,5000,300);
    ctx.fillRect(0,0,canvas.width,canvas.height);
    b=(canvas.width/2.4)|0;
    c=(canvas.height/2)|0;
    poi=[[b,c],[canvas.width-b,c]];
    byo();
}

function namnam(id,min,max,def){
    var a=document.getElementById(id);
    var b=a.value;
    if(isNaN(b))b=def;
    if(b<min)b=min;
    if(b>max)b=max;
    b=b|0;
    a.value=b;
    return b;
}

function byo(){
    var a,b,c,d,e,x,y,x1,y1,han,r;
ctx.clearRect(0,0,canvas.width,canvas.height);
ctx.globalCompositeOperation = "source-over";

if((isstart || isrend) && count<wtime){


ctx.fillStyle="rgb(211,211,211)";
ctx.fillRect(0,0,canvas.width,canvas.height);

d=futosa;
ctx.fillStyle="rgb(0,0,0)";
ctx.font=d+"px HGP創英角ポップ体";
a=document.getElementById('bun').value;
a=a.split(/\r\n|\r|\n/);

    for(b=0;b<a.length;b++){
        c=ctx.measureText(a[b]).width/2;
        ctx.fillText(a[b],canvas.width/2-c,canvas.height/2+d-a.length/2*d+b*(d+5));
    }

return;

}


if(imas[1]){

x=poi[0][0];
y=poi[0][1];

x1=poi[1][0]-x;
y1=poi[1][1]-y;
han=Math.pow(x1*x1+y1*y1,0.5)*0.6;
r=Math.atan2(y1,x1);

ctx.save();
ctx.translate(x,y);
ctx.rotate((r)%(Math.PI*2));
ctx.translate(-x,-y);
a=imas[1].width/imas[1].height;
ctx.drawImage(imas[1],x-han*a,y-han,han*2*a,han*2);


ctx.restore();


a=1-(count-wtime)/(gmax-wtime-3);
  if(document.getElementById("gya").checked)a=1-a;
if(a>1)a=1;
if(a<0)a=0;
if(!(isstart || isrend))a=0;

ctx.globalCompositeOperation = "destination-out";
ctx.fillStyle="rgba(100,100,100,"+a+")";
ctx.fillRect(0,0,canvas.width,canvas.height);

}


ctx.globalCompositeOperation = "destination-atop";
if(imas[0]){
ctx.drawImage(imas[0],0,0,canvas.width,canvas.height);
}else{
ctx.fillStyle="rgb(0,0,0)";
ctx.fillRect(0,0,canvas.width,canvas.height);
}
ctx.globalCompositeOperation = "source-over";
    

if(isstart || isrend)return;

    for(a=0;a<poi.length;a++){
        ctx.fillStyle="rgb(0,0,0)";
        ctx.fillRect(poi[a][0]-posize-1,poi[a][1]-posize-1,posize*2+2,posize*2+2);
        if(a%3===0){
            ctx.fillStyle="hsl("+(0)+",90%,50%)";
        }else if(a%3==1){
            ctx.fillStyle="hsl("+(244)+",90%,50%)";
        }else{
            ctx.fillStyle="hsl("+(111)+",90%,50%)";
        }
        ctx.fillRect(poi[a][0]-posize,poi[a][1]-posize,posize*2,posize*2);
    } 
}

function mmv(e){
    var a,x,y;
    if(!nowpo)return;
    if(isma)e.preventDefault();
    a=nowpo-1;
    loc(e);
    x=mousex+sax;
    y=mousey+say;
    

        if(x<0)x=0;
        if(x>canvas.width)x=canvas.width;
        if(y<0)y=0;
        if(y>canvas.height)y=canvas.height;
        poi[a][0]=x;
        poi[a][1]=y;

        if(!a){
            poi[1][0]=x-zah[0];
            poi[1][1]=y-zah[1];
        }


    byo();
}

function loc(e){
    var x,y,sx,sy;
    sx=document.body.scrollLeft || document.documentElement.scrollLeft;
    sy=document.body.scrollTop  || document.documentElement.scrollTop;
    
    if(isma){
        x=e.changedTouches[0].pageX-canvas.offsetLeft;
        y=e.changedTouches[0].pageY-canvas.offsetTop;
        
    }else{
        
        x=e.clientX-canvas.offsetLeft+sx;
        y=e.clientY-canvas.offsetTop+sy;
    }
    mousex=x;
    mousey=y;
}

function mdn(e){
    var a,b,c,x,y;
    if(isstart)return;
    loc(e);
    for(a=poi.length-1;a>=0;a--){

        x=poi[a][0]-mousex;
        y=poi[a][1]-mousey;
        if(Math.abs(x)<=posize && Math.abs(y)<=posize){
            if(isma)e.preventDefault();
            nowpo=a+1;
            sax=x;
            say=y;


if(!a){
                    zah=[
                        poi[a][0]-poi[1][0],
                            poi[a][1]-poi[1][1],
                                ];
}
            return;
         }



        }
    }


function yomi(a){
    var b,c;
    a=+a;
    b=document.getElementsByTagName('input')[a].files[0];
    c = new FileReader();
    c.readAsDataURL(b);
    c.onload=function(e){
        e=e.target.result;
        var image=new Image();
        image.src=e;
        imas[a]=image;
        if(isma){
            timer=setTimeout(byo,80);
        }else{
            byo();
        }
    };
}

function pre(){
    var a,x,y,x1,y1,x2,y2,grd,px,py;
    count=0;
    gmax=namnam("maisuu",10,300,40);
    futosa=namnam("futosa",1,100,30);
wtime=(gmax/7)|0;
}

function ch(){
if(!imas[1]){
alert("画像を読み込んでください><");
return;
}

    if(isstart==1){
        isstart=0;
        return;
    }
    
    document.getElementById("stb").value="ストップ";
    isstart=1;
    pre();
    timer=setTimeout(dou,0);
}

function dou(){
    var a,b;
    clearTimeout(timer);
    if(isstart===0){
        document.getElementById("stb").value="動作チェック";
        byo();
        return;
    }

a=(8000/gmax)|0;


    timer=setTimeout(dou,a);
    byo();
    count++;

if(count>=gmax)count=count%gmax;

}

function gifka(){
    var a,b,c,r;
    clearTimeout(timer);
    
    if(!imas[0] && !imas[1]){
        alert("画像を読み込んでください><");
        return;
    }
    
    mae=[];
    document.getElementsByTagName('span')[0].style.visibility="visible";
    document.getElementsByTagName('img')[0].src="";
    isrend=1;
    isstart=0;
    pre();
    ho=[];
    timer=setTimeout(douga,0);
}

function douga(){
    clearTimeout(timer);
    if(!isrend){
        document.getElementsByTagName('span')[0].style.visibility="hidden";
        ho=kari=tan8=0;
        byo();
        return;
    }
    byo();
    count++;
    document.getElementById("sin").style.width=((count/gmax*300*0.5)|0)+"px";
    document.getElementById("tyoku").innerHTML="drawing"+count+"/"+gmax;
    ho.push(ctx.getImageData(0,0,canvas.width,canvas.height));
    if(ho.length>=gmax){
        document.getElementById("tyoku").innerHTML="make palette";
        timer=setTimeout(cgif,0);
        return;
    }
    timer=setTimeout(douga,0);
}

function tome(){
    a=document.getElementsByTagName('img')[0];
    if(a.style.visibility=="visible"){
        a.style.visibility="hidden";
    }else{
        a.style.visibility="visible";
    }
}

function mdcut(){
    var a,b,c,d,e,f,g,dt,tb,ch,n1,n2;
    var x,y,z,x1,y1,z1,x2,y2,z2;
    
    ch=[];
    e=[];
    for(a=0;a<ho.length;a++){
        dt=ho[a].data;
        for(b=0;b<dt.length;b+=4){
            c=String.fromCharCode(dt[b],dt[b+1],dt[b+2]);
            if(!ch[c]){
                e.push([dt[b],dt[b+1],dt[b+2],c,0]);
                ch[c]=1;
            }
        }
    }
    
    if(e.length<=256){
        pare=[];
        for(a=0;a<e.length;a++){
            pare.push([e[a][0],e[a][1],e[a][2]]);
            ch[e[a][3]]=pare.length;
        }
        
        for(b=a;b<256;b++)pare.push([0,0,0]);
        pare.ch=ch;
        return;
    }
    
    tb=[e];
    for(f=0;f<2000;f++){
        c=0;
        g=0;
        for(b=0;b<tb.length;b++){
            if(tb[b].length<2)continue;
            if(tb[b].length>c){
                c=tb[b].length;
                g=b;
            }
        }
        
        a=tb[g];
        e=[];
        e[0]=e[1]=e[2]=256;
        x2=y2=z2=0;
        
        for(b=0;b<a.length;b++){
            c=a[b];
            if(c[0]<e[0])e[0]=c[0];
            if(c[1]<e[1])e[1]=c[1];
            if(c[2]<e[2])e[2]=c[2];
            
            if(c[0]>x2)x2=c[0];
            if(c[1]>y2)y2=c[1];
            if(c[2]>z2)z2=c[2];
        }
        
        d=[];
        d[0]=x2-e[0];
        d[1]=y2-e[1];
        d[2]=z2-e[2];
        
        c=0;
        if(d[1]>=d[0] && d[1]>=d[2])c=1;
        if(d[2]>=d[1] && d[2]>=d[0])c=2;
        
        d=e[c]+d[c]/2;
        n1=[];
        n2=[];
        for(b=0;b<a.length;b++){
            e=a[b];
            if(e[c]>d){
                n1.push(e);
            }else{
                n2.push(e);
            }
        }
        
        tb[g]=n1;
        tb.push(n2);
        if(tb.length>=255)break;
    }
    
    pare=[[0,0,0]];
    
    for(f=0;f<tb.length;f++){
        a=tb[f];
        x=y=z=0;
        for(b=0;b<a.length;b++){x+=a[b][0];y+=a[b][1];z+=a[b][2];}
        b=a.length;
        x=Math.floor(x/b);
        y=Math.floor(y/b);
        z=Math.floor(z/b);
        for(b=0;b<a.length;b++)ch[a[b][3]]=pare.length;
        pare.push([x,y,z]);
    }
    pare.ch=ch;
}

function cgif(){
    var a,b,c,d,e,im;
    clearTimeout(timer);
    
    mdcut();
    
    
    count=0;
    im=ho[0];
    tan8=[];
    
    nowbit=0;
    a=[];
    b=[71,73,70,56,57,97];
    for(c=0;c<6;c++)putbit(a,b[c],8);
    b=im.width;
    putbit(a,b>>0 & 0xFF,8);
    putbit(a,b>>8 & 0xFF,8);
    b=im.height;
    putbit(a,b>>0 & 0xFF,8);
    putbit(a,b>>8 & 0xFF,8);
    
    putbit(a,1,1);//共通パレ
    putbit(a,7,3);//画素1ドット
    putbit(a,0,1);//ソート
    putbit(a,7,3);
    putbit(a,0,8);//背景色
    putbit(a,0,8);//縦横比?
    
    
    
    for(c=0;c<256;c++){
        for(d=0;d<3;d++){
            putbit(a,pare[c][d],8);
        }
    }
    
    //Application Extension
    
    putbit(a,33,8);
    putbit(a,255,8);
    putbit(a,11,8);
    
    b="NETSCAPE2.0";
    for(c=0;c<11;c++)putbit(a,b.charCodeAt(c),8);
    
    putbit(a,3,8);
    putbit(a,1,8);//?
    
    b=0;//回数
    putbit(a,b>>0 & 0xFF,8);
    putbit(a,b>>8 & 0xFF,8);
    
    putbit(a,0,8);
    kari=a;
    timer=setTimeout(dset,0);  
}

function dset(){
    var a,b,c,d,e,f,g,h,z,im,tm,jisyo,n1,n2,dt,min,max,kuri,ed,sokudo;
    clearTimeout(timer);
    if(!isrend){
        document.getElementsByTagName('span')[0].style.visibility="hidden";
        ho=kari=tan8=0;
        byo();
        return;
    }
    document.getElementById("sin").style.width=(((count/gmax*0.4+0.6)*300)|0)+"px";
    document.getElementById("tyoku").innerHTML="compression"+count+"/"+gmax;
    
    //Graphic Control Extension
    a=kari;
    im=ho[count];
    putbit(a,33,8);
    putbit(a,249,8);
    putbit(a,4,8);
    
    putbit(a,0,7);//3項目スルー
    putbit(a,1,1);//透過する
    
    sokudo=(1500/gmax)|0;



    putbit(a,sokudo>>0 & 0xFF,8);
    putbit(a,sokudo>>8 & 0xFF,8);
    putbit(a,0,8);//透過パレ番
    putbit(a,0,8);
    
    //Image Data
    putbit(a,44,8);
    putbit(a,0,16);//左ずれ
    putbit(a,0,16);//上ずれ
    b=im.width;
    putbit(a,b>>0 & 0xFF,8);
    putbit(a,b>>8 & 0xFF,8);
    b=im.height;
    putbit(a,b>>0 & 0xFF,8);
    putbit(a,b>>8 & 0xFF,8);
    
    putbit(a,0,8);//5項目スルー
    
    min=8;
    putbit(a,min,8);//最小ビット
    
    c=nowbit;
    b=lzwe(im,min);
    nowbit=c;
    
    h=0;
    c=b.length/8;
    for(d=0;d<1000;d++){
        e=c;
        if(e>255)e=255;
        c-=e;
        putbit(a,e,8);
        for(f=0;f<e;f++){
            for(g=0;g<8;g++){
                a[nowbit]=b[h]?1:0;
                nowbit++;
                h++;
            }
        }
        if(c<=0)break;
    }
    
    putbit(a,0,8);
    ho[count]=0;
    
    count++;
    
    if(count>=ho.length){
        putbit(a,59,8);
    }else{
        if(a.length>8000000){
            tan8.push(to8(a));
            kari=[];
            nowbit=0;
        }
    }
    if(count<ho.length){
        timer=setTimeout(dset,0);
    }else{
        timer=setTimeout(rend,0);
    }
}

function to8(a){
    var b,c,d,e;
    b=new Uint8Array(Math.ceil(a.length/8));
    d=0;
    for(c=0;c<b.length;c++){
        for(e=0;e<8;e++){
            b[c]+=a[d]<<(7-e);
            d++;
        }
    }
    return b;
    
}

function rend(){
    var a,b,c,d,e,src,blob,img;
    if(!tan8.length){
        b=to8(kari);
    }else{
        tan8.push(to8(kari));
        c=0;
        for(a=0;a<tan8.length;a++)c+=tan8[a].length;
        b=new Uint8Array(c);
        d=0;
        for(a=0;a<tan8.length;a++){
            for(c=0;c<tan8[a].length;c++){
                b[d]=tan8[a][c];
                d++;
            }
        }
    }
    a=((b.length/1024/1024*100)|0)/100+"Mb";
    document.getElementById("mega").innerHTML=a;
    
    blob = new Blob([b], {'type': 'image/gif'});
    b= window.URL || window.webkitURL;
    src=b.createObjectURL(blob);
    img = document.getElementsByTagName('img')[0];
    img.src=src;
    img.style.visibility="visible";
    
    document.getElementsByTagName('span')[0].style.visibility="hidden";
    document.getElementById("tome").style.visibility="visible";
    kari=tan8=isrend=0;
    byo();
    
}

function lzwe(im,min){
    var a,b,c,d,e,jisyo,kuri,max,len,mmin,ch,n1,n2,n3,nm;
    ch=pare.ch;
    a=[];nm=[];
    
    nowbit=0;
    dt=im.data;
    
    kuri=1<<min;
    ed=kuri+1;
    len=ed+1;
    min++;
    mmin=min;
    max=1<<min;
    
    b=0;
    nowpin=7;
    jisyo=[];
    for(c=0;c<len;c++)jisyo[c+"a"]=c;
    putbit2(a,kuri,min);
    
    for(z=0;z<1000000;z++){
        
        e=c=ch[String.fromCharCode(dt[b],dt[b+1],dt[b+2])];
        if(c==mae[b])c=0;
        nm[b]=e;
        
        
        
        n3=n1=jisyo[c+"a"]+"a";
        if(b+4>=dt.length){
            putbit2(a,jisyo[c+"a"],min);
            break;
        }
        for(d=0;d<1000000;d++){
            
            e=c=ch[String.fromCharCode(dt[b+4],dt[b+5],dt[b+6])];
            if(c==mae[b+4])c=0;
            nm[b+4]=e;
            n2=n1+jisyo[c+"a"]+"a";
            
            if(!jisyo[n2]){
                jisyo[n2]=len;
                len++;
                putbit2(a,jisyo[n3],min);
                if(len>=max+1){
                    min++;
                    max=1<<min;
                    if(min>12){
                        putbit2(a,kuri,12);
                        min=mmin;
                        max=1<<min;
                        len=ed+1;
                        jisyo=[];
                        for(c=0;c<len;c++)jisyo[c+"a"]=c;
                    }
                }
                break;
            }else{
                n3=n2;
                n1=jisyo[n2]+"a";
            }
            b+=4;
        }
        b+=4;
        if(b>=dt.length)break;
    }
    putbit2(a,ed,min);
    jisyo=[];
    mae=nm;
    return a;
}

function putbit2(retu,atai,naga){
    for(var a=0;a<naga;a++){
        retu[nowbit+nowpin]=(atai>>a)&1;
        nowpin--;
        if(nowpin<0){
            nowpin=7;
            nowbit+=8;
        }
    }
}

function putbit(retu,atai,naga){
    for(var a=0;a<naga;a++){
        retu[nowbit+a]=(atai>>(naga-a-1))&1;
    }
    nowbit+=naga;
}
              
            
!
999px

Console