Gif frames to new image?

Just starting out? Need help? Post your questions and find answers here.
vwidmer
Enthusiast
Enthusiast
Posts: 282
Joined: Mon Jan 20, 2014 6:32 pm

Gif frames to new image?

Post by vwidmer »

I am trying to load a gif from memory and create a new image.

Example:
GIFIMG1 has 200 frames
I want to create a new image GIFIMG2 with frames 20-30 from GIFIMG1

Right now I am just trying to even copy one but it is my first time working with images in PB maybe some one can help me and or point me in the right direction. Thanks

Code: Select all

UseGIFImageDecoder()

;- DataSection
DataSection
  GIFIMG1:
  IncludeBinary "a.gif"
EndDataSection

#imgRaw=1
#imgCut=2

Procedure Gif2NewIMG()
  
  CatchImage(#imgRaw, ?GIFIMG1)
  
  CreateImage(#imgCut,150, 150)
  StartDrawing(ImageOutput(#imgCut))
  SetImageFrame(#imgRaw, 100)
  AddImageFrame(#imgCut, ImageFrameCount(#imgCut)-1)
  SetImageFrame(#imgCut, ImageFrameCount(#imgCut)-1)
  CopyImage(#imgRaw, #imgCut)
  DrawImage(ImageID(#imgCut), 0,0)
  StopDrawing()
EndProcedure

OpenWindow(0, 100, 100, 400, 400, "")
 
  imgG = ImageGadget(#PB_Any, 0, 0, 150, 150,0)
  AddWindowTimer(0, 1, 150)
  
  Gif2NewIMG()
  Debug "Now there is " + Str(ImageFrameCount(#imgRaw)) + " frames"
    Debug "Now there is " + Str(ImageFrameCount(#imgCut)) + " frames"
 
 ;Frame=120
  Repeat
    Event = WaitWindowEvent()
   
    If Event = #PB_Event_Timer
      SetImageFrame(#imgCut, Frame)
      Frame+1
      If Frame >= ImageFrameCount(#imgCut)
       
      Frame = 0 : EndIf
     
     
      SetGadgetState(imgG,ImageID(#imgCut))
    EndIf
   
  Until Event = #PB_Event_CloseWindow
WARNING: I dont know what I am doing! I just put stuff here and there and sometimes like magic it works. So please improve on my code and post your changes so I can learn more. TIA
codeit
User
User
Posts: 62
Joined: Sat Apr 15, 2017 5:53 pm
Location: Leicestershire

Re: Gif frames to new image?

Post by codeit »

There is a website that you can upload your gif and it splits it up for you.
https://ezgif.com/split

hope this helps
vwidmer
Enthusiast
Enthusiast
Posts: 282
Joined: Mon Jan 20, 2014 6:32 pm

Re: Gif frames to new image?

Post by vwidmer »

Yes I found lots of sites that can do that. I was hoping to do it in PB
thanks
WARNING: I dont know what I am doing! I just put stuff here and there and sometimes like magic it works. So please improve on my code and post your changes so I can learn more. TIA
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Gif frames to new image?

Post by JHPJHP »

Removed; post ignored.
Last edited by JHPJHP on Sat May 26, 2018 8:43 pm, edited 2 times in total.
vwidmer
Enthusiast
Enthusiast
Posts: 282
Joined: Mon Jan 20, 2014 6:32 pm

Re: Gif frames to new image?

Post by vwidmer »

Well this is what I came up with.. Probably not the best but kinda sorta sometimes work :)

Code: Select all

UseGIFImageDecoder()

#imgRaw=1
#imgCut=2
#imgBuf=3

Procedure FrameSlicer(fsStart.i,fsEnd.i,fsX.i,fsY.i)
  LoadImage(#imgRaw, "a.gif")
  
  CreateImage(#imgCut, fsX, fsY)
  
  SetImageFrame(#imgRaw, fsStart)
  ResizeImage(#imgRaw,fsX,fsY)
  CopyImage(#imgRaw, #imgBuf)
  
  StartDrawing(ImageOutput(#imgCut))
  DrawImage( ImageID(#imgBuf), 0,0)
  StopDrawing()
  
  For i = (fsStart + 1) To fsEnd
  FreeImage(#imgRaw)
  LoadImage(#imgRaw, "a.gif")
  FreeImage(#imgBuf)
  SetImageFrame(#imgRaw, i)
  ResizeImage(#imgRaw,fsX,fsY)
  CopyImage(#imgRaw, #imgBuf)
  
  AddImageFrame(#imgCut)
  StartDrawing(ImageOutput(#imgCut))
  DrawImage( ImageID(#imgBuf), 0,0)
  StopDrawing()
  Next i
EndProcedure

;Select frames from 100 to 110 with image size of 150 x 150
FrameSlicer(100,110,150,150)
WARNING: I dont know what I am doing! I just put stuff here and there and sometimes like magic it works. So please improve on my code and post your changes so I can learn more. TIA
Post Reply