Skip to content

Commit 34ca59b

Browse files
author
Brian Yanosik
committed
Initial Release
0 parents  commit 34ca59b

File tree

12 files changed

+525
-0
lines changed

12 files changed

+525
-0
lines changed

.craftplugin

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"pluginName":"craft-twig-imagebase64","pluginDescription":"base64 image encoding","pluginVersion":"1.0.0","pluginAuthorName":"kisonay","pluginVendorName":"kisonay","pluginAuthorUrl":"http://github.com","pluginAuthorGithub":"kisonay","codeComments":"yes","pluginComponents":["twigextensions"],"consolecommandName":"","controllerName":"","cpsectionName":"","elementName":"","fieldName":"","modelName":"","purchasableName":"","recordName":"","serviceName":"","taskName":"","utilityName":"","widgetName":"","apiVersion":"api_version_3_0"}

.gitignore

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# CRAFT ENVIRONMENT
2+
.env.php
3+
.env.sh
4+
.env
5+
6+
# COMPOSER
7+
/vendor
8+
9+
# BUILD FILES
10+
/bower_components/*
11+
/node_modules/*
12+
/build/*
13+
/yarn-error.log
14+
15+
# MISC FILES
16+
.cache
17+
.DS_Store
18+
.idea
19+
.project
20+
.settings
21+
*.esproj
22+
*.sublime-workspace
23+
*.sublime-project
24+
*.tmproj
25+
*.tmproject
26+
.vscode/*
27+
!.vscode/settings.json
28+
!.vscode/tasks.json
29+
!.vscode/launch.json
30+
!.vscode/extensions.json
31+
config.codekit3
32+
prepros-6.config

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# craft-twig-imagebase64 Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).
6+
7+
## 1.0.0 - 2018-07-22
8+
### Added
9+
- Initial release

LICENSE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2018 kisonay
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<img src="resources/img/media-encoder.svg" width="120">
2+
3+
# Twig Image Base64 Encoding
4+
5+
A simple Twig extension to create base64-encoded strings from Craft [Image] Assets in your Twig templates.
6+
7+
<!--- ## Installation
8+
9+
Find it in the Craft Plugin Store or simply install via Composer from your command line composer require "kisonay/craft-twig-imagebase64" --->
10+
11+
## Requirements
12+
13+
This Twig extension requires that you pass an instance of a Craft [`Asset`](https://docs.craftcms.com/api/v3/craft-elements-asset.html) in your Twig template. The extension will die gracefully if anything other than that is passed in as the first parameter.
14+
15+
## Usage
16+
17+
### As a Twig Function
18+
19+
###### With default options
20+
21+
{{ image64(asset) }}
22+
23+
###### With `inline` set to `true`
24+
25+
{{ image64(asset, true) }}
26+
27+
This will return the base64-encoded string in a [data URI scheme](http://en.wikipedia.org/wiki/Data_URI_scheme). The default value is `false`.
28+
29+
### As a Twig Filter
30+
31+
{{ asset|image64 }}

composer.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"name": "kisonay/craft-twig-imagebase64",
3+
"description": "Base64 encode images within twig templates.",
4+
"type": "craft-plugin",
5+
"version": "1.0.0",
6+
"keywords": [
7+
"craft",
8+
"cms",
9+
"craftcms",
10+
"craft-plugin",
11+
"craft-twig-imagebase64"
12+
],
13+
"support": {
14+
"docs": "https://github.com/kisonay/craft-twig-imagebase64/blob/master/README.md",
15+
"issues": "https://github.com/kisonay/craft-twig-imagebase64/issues"
16+
},
17+
"license": "MIT",
18+
"authors": [{
19+
"name": "kisonay",
20+
"homepage": "https://github.com/kisonay/"
21+
}],
22+
"require": {
23+
"craftcms/cms": "^3.0.0"
24+
},
25+
"autoload": {
26+
"psr-4": {
27+
"kisonay\\crafttwigimagebase64\\": "src/"
28+
}
29+
},
30+
"extra": {
31+
"name": "Image Base64",
32+
"handle": "craft-twig-imagebase64",
33+
"hasCpSettings": false,
34+
"hasCpSection": false,
35+
"changelogUrl": "https://raw.githubusercontent.com/kisonay/craft-twig-imagebase64/master/CHANGELOG.md",
36+
"class": "kisonay\\crafttwigimagebase64\\Crafttwigimagebase64"
37+
}
38+
}

resources/img/media-encoder.svg

Lines changed: 53 additions & 0 deletions
Loading

src/Crafttwigimagebase64.php

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<?php
2+
/**
3+
* craft-twig-imagebase64 plugin for Craft CMS 3.x
4+
*
5+
* base64 image encoding
6+
*
7+
* @link http://github.com
8+
* @copyright Copyright (c) 2018 kisonay
9+
*/
10+
11+
namespace kisonay\crafttwigimagebase64;
12+
13+
use kisonay\crafttwigimagebase64\twigextensions\Crafttwigimagebase64TwigExtension;
14+
15+
use Craft;
16+
use craft\base\Plugin;
17+
use craft\services\Plugins;
18+
use craft\events\PluginEvent;
19+
20+
use yii\base\Event;
21+
22+
/**
23+
* Craft plugins are very much like little applications in and of themselves. We’ve made
24+
* it as simple as we can, but the training wheels are off. A little prior knowledge is
25+
* going to be required to write a plugin.
26+
*
27+
* For the purposes of the plugin docs, we’re going to assume that you know PHP and SQL,
28+
* as well as some semi-advanced concepts like object-oriented programming and PHP namespaces.
29+
*
30+
* https://craftcms.com/docs/plugins/introduction
31+
*
32+
* @author kisonay
33+
* @package Crafttwigimagebase64
34+
* @since 1.0.0
35+
*
36+
*/
37+
class Crafttwigimagebase64 extends Plugin
38+
{
39+
// Static Properties
40+
// =========================================================================
41+
42+
/**
43+
* Static property that is an instance of this plugin class so that it can be accessed via
44+
* Crafttwigimagebase64::$plugin
45+
*
46+
* @var Crafttwigimagebase64
47+
*/
48+
public static $plugin;
49+
50+
// Public Properties
51+
// =========================================================================
52+
53+
/**
54+
* To execute your plugin’s migrations, you’ll need to increase its schema version.
55+
*
56+
* @var string
57+
*/
58+
public $schemaVersion = '1.0.0';
59+
60+
// Public Methods
61+
// =========================================================================
62+
63+
/**
64+
* Set our $plugin static property to this class so that it can be accessed via
65+
* Crafttwigimagebase64::$plugin
66+
*
67+
* Called after the plugin class is instantiated; do any one-time initialization
68+
* here such as hooks and events.
69+
*
70+
* If you have a '/vendor/autoload.php' file, it will be loaded for you automatically;
71+
* you do not need to load it in your init() method.
72+
*
73+
*/
74+
public function init()
75+
{
76+
parent::init();
77+
self::$plugin = $this;
78+
79+
// Add in our Twig extensions
80+
Craft::$app->view->registerTwigExtension(new Crafttwigimagebase64TwigExtension());
81+
82+
// Do something after we're installed
83+
Event::on(
84+
Plugins::class,
85+
Plugins::EVENT_AFTER_INSTALL_PLUGIN,
86+
function (PluginEvent $event) {
87+
if ($event->plugin === $this) {
88+
// We were just installed
89+
}
90+
}
91+
);
92+
93+
/**
94+
* Logging in Craft involves using one of the following methods:
95+
*
96+
* Craft::trace(): record a message to trace how a piece of code runs. This is mainly for development use.
97+
* Craft::info(): record a message that conveys some useful information.
98+
* Craft::warning(): record a warning message that indicates something unexpected has happened.
99+
* Craft::error(): record a fatal error that should be investigated as soon as possible.
100+
*
101+
* Unless `devMode` is on, only Craft::warning() & Craft::error() will log to `craft/storage/logs/web.log`
102+
*
103+
* It's recommended that you pass in the magic constant `__METHOD__` as the second parameter, which sets
104+
* the category to the method (prefixed with the fully qualified class name) where the constant appears.
105+
*
106+
* To enable the Yii debug toolbar, go to your user account in the AdminCP and check the
107+
* [] Show the debug toolbar on the front end & [] Show the debug toolbar on the Control Panel
108+
*
109+
* http://www.yiiframework.com/doc-2.0/guide-runtime-logging.html
110+
*/
111+
Craft::info(
112+
Craft::t(
113+
'craft-twig-imagebase64',
114+
'{name} plugin loaded',
115+
['name' => $this->name]
116+
),
117+
__METHOD__
118+
);
119+
}
120+
121+
// Protected Methods
122+
// =========================================================================
123+
124+
}

src/icon-mask.svg

Lines changed: 52 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)