10a7ce71fSopenharmony_ci#!/usr/bin/env python3
20a7ce71fSopenharmony_ci
30a7ce71fSopenharmony_ci# Copyright (c) 2021 Huawei Device Co., Ltd.
40a7ce71fSopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License");
50a7ce71fSopenharmony_ci# you may not use this file except in compliance with the License.
60a7ce71fSopenharmony_ci# You may obtain a copy of the License at
70a7ce71fSopenharmony_ci#
80a7ce71fSopenharmony_ci#     http://www.apache.org/licenses/LICENSE-2.0
90a7ce71fSopenharmony_ci#
100a7ce71fSopenharmony_ci# Unless required by applicable law or agreed to in writing, software
110a7ce71fSopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS,
120a7ce71fSopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
130a7ce71fSopenharmony_ci# See the License for the specific language governing permissions and
140a7ce71fSopenharmony_ci# limitations under the License.
150a7ce71fSopenharmony_ci
160a7ce71fSopenharmony_ciimport os
170a7ce71fSopenharmony_ciimport sys
180a7ce71fSopenharmony_cifrom PIL import Image
190a7ce71fSopenharmony_ci
200a7ce71fSopenharmony_ciif len(sys.argv) < 2:
210a7ce71fSopenharmony_ci	print('Usage: {} gif outdir'.format(sys.argv[0]))
220a7ce71fSopenharmony_ci	exit(-1)
230a7ce71fSopenharmony_ci
240a7ce71fSopenharmony_cigifimg = sys.argv[1]
250a7ce71fSopenharmony_cioutdir = sys.argv[2]
260a7ce71fSopenharmony_ci
270a7ce71fSopenharmony_ciim = Image.open(gifimg)
280a7ce71fSopenharmony_ciif not os.path.exists(outdir):
290a7ce71fSopenharmony_ci	os.mkdir(outdir)
300a7ce71fSopenharmony_ci
310a7ce71fSopenharmony_cii = 0
320a7ce71fSopenharmony_citry:
330a7ce71fSopenharmony_ci	while True:
340a7ce71fSopenharmony_ci		im.seek(i)
350a7ce71fSopenharmony_ci		im.save(os.path.join(outdir, 'frame' + str(i) + '.png'))
360a7ce71fSopenharmony_ci		i += 1
370a7ce71fSopenharmony_ciexcept:
380a7ce71fSopenharmony_ci	pass
390a7ce71fSopenharmony_ciprint('images:', i)
40