Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Creating GIF Animation From Local Images File

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Extensions
View previous topic :: View next topic  
Author Message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Mon Jun 03, 2019 9:12 am    Post subject: Creating GIF Animation From Local Images File This post has 1 review(s) Reply with quote

Graphics Interchange Format (GIF), is a file extension for an often animated raster graphics file. GIF created by using several bitmap images such as JPEG, BMP, PNG, and many other images formats.

The idea to create a GIF file (animation) is by shows each image by time interval (frames rate) and collection of several shown image usually called as a sprite.

Since CE build by default to handle show three images format type (JPEG, BMP, PNG, and plus ICO); then need some custom functions to show/displaying a GIF format type file to get animation on parent objects such as CEForm and CEPanel.

Storing several images to CE Table File will make a CT File size growing to big size. You can imagine if you save 100 images file to CE Table, it will make your CT File size bigger.

So, we able to get the images and use it to creating a GIF animation from the internet or online file storage, but how if the internet speed is slow?. You can find some functions to creating a GIF animation on this forum if you are not too lazy to find it.

Then, here is a small function use to creating a GIF animation with source images load from local disk.

Code:
function framesAsGif(parentImage, frameDir, frameNumber, speed)

 local pics={}
 local t = {}
 --local path = TrainerOrigin or getMainForm() or frameDir

 function createPictureImg(data)
  local picture = createPicture()
  local stream = createStringStream(data)
  picture.loadFromStream(stream)
  stream.destroy()
  return picture
 end

 for i=1, frameNumber do  ---- change here with total number of frames
  if i < 10 then
  var = '00'..i
  elseif i > 9 and i < 100 then
  var = '0'..i
 else
  var = i
 end
 local frame = 'frame_'..var..'.png'
 table.insert(t,frame)
 end

 for i=1,frameNumber do
  local file = io.open(frameDir..t[i],"rb")  --- change here for path name
  if not file then return nil end
  local pic = file:read("*a")
  local img = createPictureImg(pic)
  pics[i] = img
 end

 pics.currentPicture=1
 local var = 0

 function createGifsy()
  t.enabled = true
  parentImage.Picture=pics[pics.currentPicture]
  if pics.currentPicture == frameNumber then
  t.enabled = false
  t.destroy()
  else
  pics.currentPicture=(pics.currentPicture % frameNumber)+1
  end
 end

 t = createTimer()
 t.interval = speed
 t.enabled = true
 t.onTimer =  createGifsy
end



You can copy paste the script above and save it as a Lua file to CE autorun folder or directly use on your project script.

Explanation:
Code:

function framesAsGif(parentImage, frameDir, frameNumber, speed)


framesAsGif = The function name
frameDir = String, The directory and folder name where the source images located
frameNumber = Number, Total of the images on the directory/folder
speed = Number, The number to control the animation speed. Small number = fast, big number = slow
NOTE: by default, the images name MUST BE 'frame_001', 'frame_002' and so on

SAMPLE:

Code:
-------------------------- TEST CREATING CIRCLE PROGRESS BAR WITH PERCENT
f = createForm()
f.setSize(300,300)
f.Color = '0x000000'
f.Position = 'poScreenCenter'

pbImage = createImage(f)
pbImage.setSize(350,200)
pbImage.stretch = true
pbImage.setPosition(-25,30)

btn = createButton(f)
btn.setSize(50,30)
btn.setPosition(240,260)
btn.Caption = 'Play'

mypath = 'E://GIFframesSource//' -- this contains source images frames, default name = frame_xxx

function gif()
 framesAsGif(pbImage, mypath, 102, 100)
end

function exit()
 closeCE()
 return caFree()
end

f.show()
btn.onClick = gif
f.onClose = exit


If you want to test by yourself here is the link for source images file which you able to download (copy paste to your web browser):

https://mega.nz/#!T5tFlaSD!D0rftajCO_9Y0-oeoeEWSOwK2vdbuXTe0Y_oM7G8BII

Edit, modify or share all of these is on my pleasure. It's free!

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 31

Joined: 16 Feb 2017
Posts: 1234

PostPosted: Mon Jun 03, 2019 12:47 pm    Post subject: Reply with quote

This is a more regular version of the previous version.
The other code was a little more complicated
(Created with Corroder and FreeER, gif code.)
and I liked the following code.

Picture - Path - Number of Photos - Execution Speed ...
Code:
framesAsGif(pbImage, mypath, 102, 100)


Congratulations. Regular and nice work.

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
AylinCE
Grandmaster Cheater Supreme
Reputation: 31

Joined: 16 Feb 2017
Posts: 1234

PostPosted: Thu Jul 04, 2019 3:44 pm    Post subject: Reply with quote

@Corroder: Can you edit this code for multiple gifs?
and "findTableFile" to load images from the table.
Thanks.

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Fri Jul 05, 2019 5:54 am    Post subject: Reply with quote

Here is code to load frames image from table files.

Code:
--===============================================================---
-- Beware to give every image frames with correct name
-- by default the image frames name = frame_x (x=number start from 0)
-- and give attention with image file extension type
-- Example to use :
-- framesAsGif(pbImage, 47, 100, 'png')
-- pbImage = your CEImage name
-- 47 = total number of frames
-- png = your image file extension
--==============================================================----
-- Add all your image frames to CE TABLE FILE
--===============================================================---


function framesAsGif(parentImage, frameNumber, speed, extension)
 local pics={}
 local t = {}
 for i=0, frameNumber do
  if i < 10 then
   var = '0'..i
  elseif i > 9 and i < 100 then
   var = i
  end
 local frame = 'frame_'..var..'.'..extension
 table.insert(t,frame)
 end
 for i=1,frameNumber do
  local file = findTableFile(t[i])
  if not file then return nil end
  p=createPicture()
  p.loadFromStream(file.Stream)
  pics[i] = p
 end
 pics.currentPicture=1
 function createGifsy()
  t.enabled = true
  parentImage.Picture=pics[pics.currentPicture]
  if pics.currentPicture == frameNumber then
  pics.currentPicture=1  -- for looping
 -- this 2 lines below to stop animation if don't want loop
 -- t.enabled = false
 -- t.destroy()
  else
  pics.currentPicture=(pics.currentPicture % frameNumber)+1
  end
 end
 t = createTimer()
 t.interval = speed
 t.enabled = true
 t.onTimer = createGifsy
end


-------------------------- TEST CREATING CIRCLE PROGRESS BAR WITH PERCENT
f = createForm()
f.setSize(300,300)
f.Color = '0x000000'
f.Position = 'poScreenCenter'

pbImage = createImage(f)
pbImage.setSize(200,200)
pbImage.stretch = true
pbImage.setPosition(10,10)

btn = createButton(f)
btn.setSize(50,30)
btn.setPosition(240,260)
btn.Caption = 'Play'

function gif()
 framesAsGif(pbImage, 47, 100, 'png')
end

function exit()
 closeCE()
 return caFree()
end

f.show()
btn.onClick = gif
f.onClose = exit


To create multiple gifs, I don't know the simple way to do that since I don't know/not find to get 'File Name' added to CE Table File.
Maybe DB can help how to count how many file on CE Table Files and to get the filename for each CE Table Files.
If we solve these matters then we possible to make multiple GIF.

Meanwhile, if you must, then just make 2 or 3 functions from that script above and change some names inside the functions:
1. The function name: framesAsGif1, framesAsGif2, etc
2. Change 'frame_' inside the function according to your GIF file name: example: 'img_00, img_01, etc'
3. Change function createGifsy() to function createGifsy1(), function createGifs2y(), etc
4. Change the timer name., example: t1, t2, t3 etc

then call the function like this:

Code:
framesAsGif(pbImage, 47, 100, 'png')
framesAsGif2(pbImage2, 10, 200, 'gif')
// and so on


I just think, why you want load images from Table File considering the CT/CETRAINER/EXE file will grow up to big size by add some files to CE Table File.

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 31

Joined: 16 Feb 2017
Posts: 1234

PostPosted: Fri Jul 05, 2019 8:20 am    Post subject: Reply with quote

Corroder wrote:

Meanwhile, if you must, then just make 2 or 3 functions from that script above and change some names inside the functions:
1. The function name: framesAsGif1, framesAsGif2, etc
2. Change 'frame_' inside the function according to your GIF file name: example: 'img_00, img_01, etc'
3. Change function createGifsy() to function createGifsy1(), function createGifs2y(), etc
4. Change the timer name., example: t1, t2, t3 etc

then call the function like this:

Code:
framesAsGif(pbImage, 47, 100, 'png')
framesAsGif2(pbImage2, 10, 200, 'gif')
// and so on


Thanks @Corroder.
I think the information you provided will solve the problem.


Corroder wrote:
I just think, why you want load images from Table File considering the CT/CETRAINER/EXE file will grow up to big size by add some files to CE Table File.


This is a small game project.
I will use 3 characters and each character has 3 different moves.
I'll use low file sizes.
But when the concept becomes a game; Size is losing its importance. Smile

Thanks again.

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Extensions All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites