Skip to content

Instantly share code, notes, and snippets.

@horst-n
Created June 21, 2014 00:21
Show Gist options
  • Save horst-n/ef70453e1007c172a162 to your computer and use it in GitHub Desktop.
Save horst-n/ef70453e1007c172a162 to your computer and use it in GitHub Desktop.
this is a simple template code that test the new pageimage methods regarding suffix!
<?php
// test for static helper function pageimage::addSuffix
foreach(array(
'suf1' => '/www/htdocs/site/assets/files/1001/basename.jpg',
'suf2' => '/www/htdocs/site/assets/files/1001/basename.100x0.jpg',
'suf3' => '/www/htdocs/site/assets/files/1001/basename.100x0nw.jpg',
'suf4' => '/www/htdocs/site/assets/files/1001/basename.100x0nw-suf4.jpg',
'suf5' => '/www/htdocs/site/assets/files/1001/basename.100x0nw-suf7.jpg',
'suf6' => '/www/htdocs/site/assets/files/1001/basename.100x0nw-suf7-suf6-suf1.jpg',
'suf7' => '/www/htdocs/site/assets/files/1001/basename.100x0nw-suf7-suf6-suf1.jpg',
'suf8' => '/www/htdocs/site/assets/files/1001/basename.100x0-suf8.jpg',
'suf9' => '/www/htdocs/site/assets/files/1001/basename.100x0-suf8.jpg',
'-suf1' => '/www/htdocs/site/assets/files/1001/basename.100x0nw-suf8-suf1.jpg',
'su-f1' => '/www/htdocs/site/assets/files/1001/basename.100x0-suf8.jpg',
'suf1-' => '/www/htdocs/site/assets/files/1001/basename.100x0-suf8.jpg',
) as $k=>$v) {
echo "$k = " . pageimage::addSuffix($v, $k) . '<br />';
}
// test for suffixes with pageimage
$img = $page->images->first();
$img->removeVariations();
foreach(array('suf1','suf2','suf3') as $suffix) {
foreach(array(100, 200, 300) as $width) {
$options = array('suffix'=>$suffix);
$image = $img->width($width, $options);
echo "{$image->name}<br/>";
}
}
// test for pageimage::getVariations with basic variation names
$a = $img->getVariations();
echo count($a);
foreach($a as $pi) {
echo "<br/>$pi->name";
}
echo "<br/>";
// test for pageimage::getFileBySuffix
foreach(array('thumb1','thumb2','thumb3') as $thumb) {
$orig = $img->filename;
$vari = pageimage::addSuffix($orig, $thumb);
if(copy($orig, $vari)) {
echo "$thumb = " . $img->getFileBySuffix($thumb) . "<br/>";
}
}
// test for pageimage::getFileBySuffix with partial
foreach(array('thumb4','thumb5','thumb6') as $thumb) {
$orig = $img->filename;
$vari = pageimage::addSuffix($orig, 'optim');
$vari = pageimage::addSuffix($vari, $thumb);
if(copy($orig, $vari)) {
echo "$thumb = " . $img->getFileBySuffix($thumb, true) . "<br/>";
}
}
// test for pageimage::getVariations with all variation names !!
// also "basename.-suffix.jpg"
$a = $img->getVariations();
echo count($a);
foreach($a as $pi) {
echo "<br/>$pi->name";
}
echo "<br/>";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment