アプリ関連ニュース
- 2021年12月14日
- 技術情報
Converting images into a pdf in python
Last weekend, my friend asked me to help him something about rearranging images and converting them into a pdf with only portrait view and sorting by modified date . But the images were not sorted by that and some in landscape. They were in chaos. Actually there are many online tools to do that. But most of them were not compatible with all what I wanted. Then I decided to do with a python program and wrote the following small code block. Let’s take a look.
I’ve used the image library called Pillow(PIL) and built-in module named os.
Overall program flow is as follow.
- Request user inputs for a pdf filename with path and image folder path to be converted.
- With os module, image files are sorted by modified date.
- Looping the sorted files, rotate the images which are in landscape, to be in portrait with the help of Pillow(PIL) and push the images into an empty list named img_list[ ].
- Finally convert the images list to a pdf.
from PIL import Image
import os
# Function to sort by modified dates
def getfiles(dirpath):
a = [s for s in os.listdir(dirpath)
if os.path.isfile(os.path.join(dirpath, s))]
a.sort(key=lambda s: os.path.getmtime(os.path.join(dirpath, s)))
return a
# declare an empty list
img_list = []
# Request user input for pdf filename and image folder path
pdf_filename = input("Enter the filename of pdfincluding path to be exported : ")
folder = input("Enter the path of images folder : ")
files = getfiles(folder) # get the files sorted by modified dates
print('Processing....')
for count, filename in enumerate(files):
image = Image.open(folder+'/'+filename) #open each file
# To change as portrait layout for landscape images
width, height = image.size
if(width>height):
image = image.transpose(Image.ROTATE_90)
# Append each processed image in img_list[]
img_list.append(image)
# All images in img_list[] are converted to a pdf
img_list[0].save(pdf_filename, "PDF" ,resolution=100.0, save_all=True, append_images=img_list[1:])
print("Done!")

This program is very simple but it can be modified to be more useful for other cases. I hope you enjoy that.
By Asahi
waithaw at 2021年12月14日 10:00:00
- 2021年12月13日
- 技術情報
Flutter boosts it’s mobile performance
Google Flutter 2.8, the latest version of open source, cross-platform toolkit for building web, mobile, and desktop applications, has been released, with some improvements in mobile performance and better service compatibilities.
Flutter 2.8′ has been released on December 8 including with Flame Modular 2D Game Engine(v1.0), a game engine built on Flutter to be able to create games faster with flutter.

Google said mobile apps built with Flutter 2.8 should be faster and use less memory. The company said it is leveraging its experience with great Google apps such as Google Pay to make Flutter more efficient and provide profiling and optimization better.
It also makes it easy to connect to back-end services like Firebase and Google Cloud. In addition to supporting the production quality of Google Ads, including major camera updates and built-in web plugins.
Furthermore Dart 2.15, a programming language update that offers improved concurrency, improved enums, and optimizations that reduce memory usage by 10%. Also offering capabilities including stateful hot reload. Google also is exploring higher-level abstractions to make it easier for developers to get running faster.
Flutter is for building cross-platform applications from a single code base. The goal is to change the way applications are created so that mobile, web, desktop, and embedded applications can be developed using a single toolset. The framework currently has 375,000 apps on the Google Play Store, as well as iOS apps available on the Apple App Store.
Yuuma
yuuma at 2021年12月13日 10:00:00
- 2021年12月10日
- 技術情報
Chart.js – 外側にテキスト表示する方法 とテキストの代わりに画像を表示する方法

最近Chart.jsというライブラリーを使って開発してるので、Chart.jsで外側にテキスト表示するには色々な方法があるのを気づきました。
というので、今回はChart PieceLabel を使って円グラフ描く方法をご紹介していきたいと思います。
必要となるパッケージをインポートします。
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://rawgit.com/beaver71/Chart.PieceLabel.js/master/build/Chart.PieceLabel.min.js"></script>
また、円グラフの表示に必要なデータを挿入します。
var data = {
datasets: [{
data: [16,11,16,30],
backgroundColor: ['#ee7571', '#438067', '#d0dfad', '#b4e1d1'],
label: '季' ,// for legend
}],
labels : ['春','夏','秋','冬'],
};
データをキャンバスに表示するためには、キャンバスを作成する必要があります。そして、スクリプトファイルを書くためには、canvas-idを取得する必要があります。
<div class="col-md-6" style="width: 40%; margin-left: 200px;">
<canvas id="pieChart" class="chart chart-pie"></canvas>
</div>
var pieChartCanvas = $("#pieChart");
PieceLabelの設定をoptionsに追加し、typeを「pie」に設定する必要もある
var pieChart = new Chart(pieChartCanvas, {
type: 'pie',
data: data,
options: pieOptions
});
var pieOptions = {
pieceLabel: {
render: function(d) {
return d.label;
},
fontColor: '#000',
position: 'outside',
arc : true,
fontSize:35,
fontFamily: '"Helvetica , "游ゴシック", sans-serif'
},
};
外側にラベル表示するには position に outside と設定する必要があります。FontColor, fontSize, fontFamily も変更したいなら、簡単にできます。
legendを非表示にしたい場合は、displayをfalseにします。
legend: {
display: false
},
その結果は:

また、renderにimageを設定して画像を表示することもできます。
render: 'image',
images: [
{ src: './images/spring.jpeg', width: 65, height: 65 },
{ src: './images/Summer.jpeg', width: 65, height: 65 },
{ src: './images/Autumn.jpeg', width: 65, height: 65 },
{ src: './images/Winter.jpeg', width: 65, height: 65 }
]
}
結果は記事の一番上にあります。
最後までお読みいただき、ありがとうございます。この記事を楽しんでいただければ幸いです。
By Ami
asahi at 2021年12月10日 10:00:00
- 2021年12月09日
- 技術情報
PHP QRコード生成ライブラリ「endroid/qr-code」
nishida at 2021年12月09日 10:00:00
- 2021年12月09日
- Web Service
Different Laravel methods firstOrNew, firstOrCreate, firstOr, and updateOrCreate
Standard methods for creating Eloquent Models like make()
, create()
, update
, and save()
. Laravel includes some other methods are that also really useful for creating and updating Models that I feel don’t get enough attention. So in this article, I’d like to go over some of these additional methods and explain how they might be useful.
1. firstOrNew
The firstOrNew
method is really useful for finding the first Model that matches some constraints or making a new one if there isn’t one that matches those constraints.
You can take a piece of code that looks like this:
$user = User::where(‘email,’$request->email)->first();
if($user === null){
$user = new User([ ‘email’ => $request->email ]);
$user->name = $request->name;
$user->save();
}
And turn it into this:
$user = User::firstOrNew( [ ‘email’ => $request->email ] );
$user->name = $request->name;
$user->save();
You may also pass an array of additional attributes to set as the second parameter if no existing Model is found:
$user = User::firstOrNew([‘email’ => request(‘email’)],[‘name’ => request(‘name’)]);
$user->save();
2.firstOrCreate
I recently found the firstOr
method while source-diving. The firstOr
method retrieves the first Model from a query, or if no matching Model is found, it will call a callback passed. This can be really useful if you need to perform extra steps when creating a user or want to do something other than creating a new user:
$user = User::where(‘email,’$request->email)->firstOr(function(){
$account = Account::create([
return User::create([
‘account_id’ => $account->id,
‘email’ => $request->email
]);
]);
});
3.firstOr
I recently found the firstOr
method while source-diving. The firstOr
method retrieves the first Model from a query, or if no matching Model is found, it will call a callback passed. This can be really useful if you need to perform extra steps when creating a user or want to do something other than creating a new user:
$user = User::where(‘email,’$request->email)->firstOr(function(){
$account = Account::create([
return User::create([
‘account_id’ => $account->id,
‘email’ => $request->email
]);
]);
});
4.updateOrCreate
The updateOrCreate
method attempts to find a Model matching the constraints passed as the first parameter. If a matching Model is found, it will update the match with the attributes passed as the second parameter. If no matching Model is found a new Model will be created with both the constraints passed as the first parameter and the attributes passed as the second parameter.
You can refactor this piece of code:
$user = User::where(‘email,’$request->email)->first();
if($user !== null){
$user->update([‘name’ => $request->name]);
}else{
$user = User::create([
‘email’ => $request->email,
‘name’ => $request->name
]);
}
To this using the updateOrCreate
method:
$user = User::updateOrCreate([
‘email’ => $request->email,
‘name’ => $request->name
]);
Tsuki
tsuki at 2021年12月09日 10:00:00