Skip to content

Commit

Permalink
add feature to have a text file, with the same name as the image, wit…
Browse files Browse the repository at this point in the history
…h resizing options in selector syntax (either comma or new line separated key=value pairs)
  • Loading branch information
owzim committed Apr 18, 2015
1 parent f9db652 commit 1c570b7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Blick.module
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @author Christian (owzim) Raunitschka <git@raunitschka.de>
* @copyright Copyright (c) 2015, Christian Raunitschka
*
* @version 0.6.1
* @version 0.7.0
*
* @filesource
*
Expand Down Expand Up @@ -50,7 +50,7 @@ class Blick extends Wire implements Module
return array(
'title' => 'Blick',
'summary' => 'A small helper module for including JS, CSS and image files',
'version' => '0.6.1',
'version' => '0.7.0',
'icon' => 'eye',
'requires' => array('PHP>=5.4','ProcessWire>=2.5.5'),
'singular' => true,
Expand Down
36 changes: 34 additions & 2 deletions owzim/blick/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @author Christian (owzim) Raunitschka <git@raunitschka.de>
* @copyright Copyright (c) 2015, Christian Raunitschka
*
* @version 0.3.1
* @version 0.4.0
*
* @filesource
*
Expand All @@ -31,7 +31,6 @@ class Image extends Asset
*/
function size($width, $height = 0, $options = null)
{

if($this->ext == 'svg') return $this;

if(!is_array($options)) {
Expand Down Expand Up @@ -66,6 +65,10 @@ function size($width, $height = 0, $options = null)
$configOptions = $this->config->imageSizerOptions;
if(!is_array($configOptions)) $configOptions = array();
$options = array_merge($defaultOptions, $configOptions, $options);
if ($textOptions = $this->getTextOptions()) {
$options = array_merge($options, $textOptions);
}


$width = (int) $width;
$height = (int) $height;
Expand Down Expand Up @@ -280,4 +283,33 @@ public function height($n = 0, $options = array())
{
return $this->size(0, $n, $options);
}

/**
* ___getTextOptions
*
* @return null|array
*/
protected function ___getTextOptions()
{
$rtn = null;
$path = "{$this->dir}/{$this->name}";
$optsTxtFile = "$path.txt";

// save pased text options in a static array
static $textOptions = null;
if (is_null($textOptions)) $textOptions = array();
// return parsed options if already exist for that specific image
if (isset($textOptions[$optsTxtFile])) return $textOptions[$optsTxtFile];

if (file_exists($optsTxtFile)) {
$rtn = array();
$content = str_replace("\n", ',', trim(file_get_contents($optsTxtFile)));
$selectors = new \Selectors($content);
foreach ($selectors as $selector) {
$rtn[$selector->field] = $selector->value;
}
}
// return an save it to static array
return $textOptions[$optsTxtFile] = $rtn;
}
}

0 comments on commit 1c570b7

Please sign in to comment.