Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #===============================================================================
- # Pokemon Sprite GIF to PNG converter
- # by Luka S.J.
- # tweaked by Mej
- #
- # Create a directory called "Convert" in your game's root folder
- # and place all the GIFs you want to convert in it.
- # Newly formatted PNGs will retain old GIF names.
- #===============================================================================
- class GifExtra
- def initialize(file=nil,viewport=nil)
- @file=file
- @sprite=SpriteWrapper.new(viewport)
- if file
- @bitmap=AnimatedBitmap.new(file)
- @sprite.bitmap=@bitmap.bitmap
- end
- end
- def totalFrames; @bitmap.totalFrames; end
- def bitmap; @bitmap.bitmap; end
- def visible=(val); @sprite.visible=val; end
- def dispose; @sprite.dispose; end
- def update
- if @bitmap
- @bitmap.update
- @sprite.update
- if self.bitmap!=@bitmap.bitmap
- oldrc=self.src_rect
- self.bitmap=@bitmap.bitmap
- self.src_rect=oldrc
- end
- end
- end
- end
- def readDirectoryFiles(directory,formats)
- files=[]
- Dir.chdir(directory){
- for i in 0...formats.length
- Dir.glob(formats[i]){|f| files.push(f) }
- end
- }
- return files
- end
- def resizePngs
- destination="./Convert/"
- search_for=["*.png"]
- @files=readDirectoryFiles(destination,search_for)
- @viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
- @viewport.z=999999
- @bar=Sprite.new(@viewport)
- @bar.bitmap=Bitmap.new(Graphics.width,34)
- pbSetSystemFont(@bar.bitmap)
- for i in 0...@files.length
- @files[i]=@files[i].gsub(/.png/) {""}
- end
- return false if !Kernel.pbConfirmMessage(_INTL("There is a total of #{@files.length} PNG(s) available for conversion. Would you like to begin the process?"))
- for i in 0...@files.length
- file=@files[i]
- width=((i*1.000)/@files.length)*Graphics.width
- @bar.bitmap.clear
- @bar.bitmap.fill_rect(0,0,Graphics.width,34,Color.new(255,255,255))
- @bar.bitmap.fill_rect(0,0,Graphics.width,32,Color.new(0,0,0))
- @bar.bitmap.fill_rect(0,0,width,32,Color.new(25*4,90*2,25*4))
- text=[["#{i}/#{@files.length}",Graphics.width/2,2,2,Color.new(255,255,255),nil]]
- pbDrawTextPositions(@bar.bitmap,text)
- next if RTP.exists?("#{destination}New/#{file}.png")
- sprite=pbBitmap("#{destination}#{file}.png")
- width=sprite.width
- height=sprite.height
- bitmap=Bitmap.new(width/2,height/2)
- bitmap.stretch_blt(Rect.new(0,0,width/2,height/2),sprite,Rect.new(0,0,width,height))
- bitmap.saveToPng("#{destination}New/#{file}.png")
- sprite.dispose
- pbWait(1)
- RPG::Cache.clear
- end
- @bar.dispose
- @viewport.dispose
- Kernel.pbMessage(_INTL("Done!"))
- end
- def decompressGifs
- destination="./Convert/"
- search_for=["*.gif"]
- @files=readDirectoryFiles(destination,search_for)
- @viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
- @viewport.z=999999
- @bar=Sprite.new(@viewport)
- @bar.bitmap=Bitmap.new(Graphics.width,34)
- pbSetSystemFont(@bar.bitmap)
- for i in 0...@files.length
- @files[i]=@files[i].gsub(/.gif/) {""}
- end
- return false if !Kernel.pbConfirmMessage(_INTL("There is a total of #{@files.length} GIF(s) available for conversion. Would you like to begin the process?"))
- for i in 0...@files.length
- file=@files[i]
- width=((i*1.000)/@files.length)*Graphics.width
- @bar.bitmap.clear
- @bar.bitmap.fill_rect(0,0,Graphics.width,34,Color.new(255,255,255))
- @bar.bitmap.fill_rect(0,0,Graphics.width,32,Color.new(0,0,0))
- @bar.bitmap.fill_rect(0,0,width,32,Color.new(25*4,90*2,25*4))
- text=[["#{i}/#{@files.length}",Graphics.width/2,2,2,Color.new(255,255,255),nil]]
- pbDrawTextPositions(@bar.bitmap,text)
- next if RTP.exists?("#{destination}#{file}.png")
- sprite=GifExtra.new("#{destination}#{file}.gif")
- frames=sprite.totalFrames
- width=sprite.bitmap.width
- height=sprite.bitmap.height
- sprite.visible=false
- if width<height
- size=height
- elsif height<width
- size=width
- else
- size=width
- end
- bitmap=Bitmap.new(size*frames,size)
- x=0
- ox=((size-width)/2)
- oy=((size-height)/2)
- rect=Rect.new(0,0,width,height)
- frames.times do
- bitmap.blt((x*size)+ox,0+oy,sprite.bitmap,rect)
- sprite.update
- x+=1
- end
- bitmap.saveToPng("#{destination}#{file}.png")
- sprite.dispose
- pbWait(1)
- RPG::Cache.clear
- end
- @bar.dispose
- @viewport.dispose
- Kernel.pbMessage(_INTL("Done!"))
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement