Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
Smashing Pixels with Imanee
Erika Heidi
June 24, 2015
Programming
1
470
Smashing Pixels with Imanee
Presenting Imanee, a simple PHP library for image manipulation
Erika Heidi
June 24, 2015
Tweet
Share
More Decks by Erika Heidi
See All by Erika Heidi
Hello Wolfi
erikaheidi
1
160
Container Images for the Cloud Native Era
erikaheidi
1
75
Creating Secure Container Images with apko
erikaheidi
0
180
Criando GitHub Actions em PHP com Minicli
erikaheidi
0
42
Building GitHub Actions in PHP with Minicli
erikaheidi
0
110
10 Code Search Tricks for Open Source
erikaheidi
2
72
The Art of Programming - Laracon Online Winter 22
erikaheidi
0
200
A Arte de Programar
erikaheidi
4
110
The Art of Programming - Codeland 2020
erikaheidi
35
11k
Other Decks in Programming
See All in Programming
TokyoR#103_DataProcessing
kilometer
0
480
ITエンジニア特化型Q&Aサイトteratailを 言語、DB、クラウドなど フルリプレイスした話
leveragestech
0
380
23年のJavaトレンドは?Quarkusで理解するコンテナネイティブJava
tatsuya1bm
1
120
Milestoner
bkuhlmann
1
240
新卒でサービス立ち上げから Hasuraを使って3年経った振り返り
yutorin
0
200
Writing Greener Java Applications
hollycummins
0
330
ポケモンで学ぶiOS 16弾丸ツアー 🚅
giginet
PRO
1
610
Git Rebase
bkuhlmann
10
1.2k
Enumを自動で網羅的にテストしてみた
estie
0
1.2k
Azure Functionsをサクッと開発、サクッとデプロイ/vscodeconf2023-baba
nina01
1
320
(新米)エンジニアリングマネージャーのしごと #RSGT2023
murabayashi
9
5.4k
Cloudflare Workersと状態管理
chimame
2
470
Featured
See All Featured
How to train your dragon (web standard)
notwaldorf
66
4.2k
Keith and Marios Guide to Fast Websites
keithpitt
407
21k
10 Git Anti Patterns You Should be Aware of
lemiorhan
643
54k
Building Your Own Lightsaber
phodgson
96
4.9k
We Have a Design System, Now What?
morganepeng
37
5.9k
Building Applications with DynamoDB
mza
85
4.9k
From Idea to $5000 a Month in 5 Months
shpigford
374
44k
The Invisible Customer
myddelton
113
12k
5 minutes of I Can Smell Your CMS
philhawksworth
198
18k
Happy Clients
brianwarren
90
5.8k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
318
19k
GitHub's CSS Performance
jonrohan
1020
430k
Transcript
None
whoami
Image manipulation • Important in any programming language • Essential
operations – Resizing – Creating Thumbnails – Cropping • More fun stuf – Filters and collages – Animated gifs
Image manipulation in PHP • GD • Imagick (Imagemagick) •
Wrappers
Resize Example: GD <?php header("Content-type: image/jpg"); $image = imagecreatefromjpeg('img01.jpg'); $width
= 200; $height = 200; $finalWidth = $width; $finalHeight = ($finalWidth * imagesy($image)) / imagesx($image); if ($finalHeight > $height) { $finalHeight = $height; $finalWidth = ($finalHeight * imagesx($image)) / imagesy($image); } $newimage = imagecreatetruecolor($finalWidth, $finalHeight); imagecopyresampled($newimage, $image, 0, 0, 0, 0, $finalWidth, $finalHeight, imagesx($image), imagesy($image)); echo imagejpeg($newimage);
Resize Example: Imagick <?php header("Content-type: image/jpg"); $image = new Imagick('img01.jpg');
$width = 200; $height = 200; $image->resizeImage($width, $height, IMAGICK::FILTER_LANCZOS, 1, true); echo $image->getImageBlob();
Resize Example: Imanee <?php include __DIR__ . '/vendor/autoload.php'; header("Content-type: image/jpg");
$imanee = new Imanee\Imanee('img01.jpg'); echo $imanee ->resize(300, 300) ->output();
Introducing: Imanee • Image manipulation for fun projects • Requirements
– PHP >= 5.4 – Imagick (php5-imagick) OR – GD (php5-gd)* • Installation – $ composer require imanee/imanee * the GD extension doesn't support animated gifs
Getting Started <?php include __DIR__ . '/vendor/autoload.php'; use Imanee\Imanee; header("Content-type:
image/jpg"); $imanee = new Imanee('img01.jpg'); echo $imanee ->resize(300, 300) ->output();
Basic operations: Thumbnail header("Content-type: image/jpg"); $imanee = new Imanee('img01.jpg'); echo
$imanee->thumbnail(300, 300) ->output();
Basic operations: Thumbnail w/ crop header("Content-type: image/jpg"); $imanee = new
Imanee('img01.jpg'); echo $imanee->thumbnail(300, 300, true) ->output();
Basic operations: Crop header("Content-type: image/jpg"); $imanee = new Imanee('img01.jpg'); echo
$imanee->crop(300, 300, 260, 0) ->output();
WRITING TEXT
Writing Text header("Content-type: image/jpg"); $imanee = new Imanee('img01.jpg'); echo $imanee->placeText('testing
imanee', Imanee::IM_POS_MID_CENTER) ->output();
Writing Text with custom Drawer header("Content-type: image/jpg"); $imanee = new
Imanee('img01.jpg'); $imanee->getDrawer() ->setFont('almonte_wood.ttf') ->setFontColor('yellow') ->setFontSize(100); echo $imanee->placeText('testing imanee!', Imanee::IM_POS_MID_CENTER) ->output();
FILTERS AND COLLAGES
Filters header("Content-type: image/jpg"); $imanee = new Imanee('img01.jpg'); echo $imanee->applyFilter('filter_bw') ->output();
Collages header("Content-type: image/jpg"); $imanee = new Imanee('img01.jpg'); echo $imanee ->placeImage('cat01.png',
Imanee::IM_POS_TOP_LEFT) ->placeImage('cat02.png', Imanee::IM_POS_TOP_RIGHT) ->output();
Animated Gifs header("Content-type: image/gif"); $frames = ['cat01.png', 'cat02.png', 'cat03.png', 'cat04.png'];
$imanee = new Imanee(); $imanee->addFrames($frames); echo $imanee->animate(30); $frames = ['cat01.png', 'cat02.png', 'cat03.png', 'cat04.png']; echo Imanee::arrayAnimate($frames, 30); echo Imanee::globAnimate(__DIR__ . '/*.png', 30);
RESOURCES
Resources • Getting Started – Documentation: http://docs.imanee.io – Simple demos:
http://imanee.io • Built with Imanee – Placephant: http://placephant.com • Try: http://placephant.com/{width}/{height} – Gifagram: [demo]
[email protected]
@erikaheidi