Skip to content

Commit

Permalink
feat: Remove ImageResizer Dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
sqwk committed Dec 8, 2022
1 parent 3d66611 commit 23f7503
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,10 @@ Drop the `Gallery` component into your page. Edit the `Select the gallery` optio

If you you want to load a dynamic gallery depending the on the url, specify the `Gallery slug` and leave `Select the gallery` set to the default `Using gallery slug`. For example, creating a CMS page with the URL `/gallery/:slug` and including the `Gallery` component with the slug `Gallery slug` set to `:slug` will display the `Test` gallery when visiting the url `/gallery/test`.

If [ImageResizer](https://octobercms.com/plugin/toughdeveloper-imageresizer) is installed, you can specify a `Max Dimension` for the gallery. This will automatically downsize original images to the longest side width/height. If the additional plugin is not installed, original images will be used.

### For static pages

Drop the `Gallery` snippet into your static page. Edit the `Select the gallery` option to choose the gallery to display. Ignore the `Gallery slug` option.

If ImageResizer is installed, you can specify a `Max Dimension` for the gallery. (See CMS pages above)

### For static pages as a custom data type (Form Widget)

Include a custom field in a static page layout as follows:
Expand All @@ -69,6 +65,16 @@ Drop the `galleries` component into your page. Edit `Gallery order` and `Results

Drop the `galleries` snippet into your static page. Edit `Gallery order` and `Results per page` as needed.

<a name="imageresizing"></a>
## Image Resizing

When the `Max Dimension` property is used for the `Gallery` component, all gallery images will be resized using October's [Resizer](https://docs.octobercms.com/3.x/extend/services/resizer.html) so that the longest side is that length in pixels. The default is `0`, which means that original images will be used.

<a name="overriding-component-template"></a>
## Overriding the Component Template

You can expand and edit the component templates if a different resizing logic is needed (for example with more options) or if you want to use your own markup. Right click on the `{% component %}` tag and click `Expand Component Partial`. (Also see [Customizing Default Markup](https://docs.octobercms.com/3.x/cms/themes/components.html#customizing-default-markup))

<a name="futurefeatures"></a>
## Future Features / In the pipeline

Expand Down
18 changes: 6 additions & 12 deletions components/Gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ class Gallery extends ComponentBase
{
public $gallery;

public $imageResizerInstalled = false;

public function componentDetails()
{
return [
Expand All @@ -28,24 +26,20 @@ public function defineProperties()
'type' => 'dropdown',
'showExternalParam' => false
],
'slug' =>[
'slug' => [
'title' => 'sqwk.gallery::lang.gallerycomponent.property.slug',
'description' => 'sqwk.gallery::lang.gallerycomponent.property.slugDescription',
'type' => 'string',
'default' => '{{ :slug }}'
]
];

if (PluginManager::instance()->hasPlugin('ToughDeveloper.ImageResizer')) {
$this->imageResizerInstalled = true;
$properties['maxDimension'] = [
],
'maxDimension' => [
'title' => 'sqwk.gallery::lang.gallerycomponent.property.maxDimension',
'description' => 'sqwk.gallery::lang.gallerycomponent.property.maxDimensionDescription',
'type' => 'string',
'default' => '640',
'default' => '0',
'showExternalParam' => false
];
}
]
];

return $properties;
}
Expand Down
4 changes: 2 additions & 2 deletions components/gallery/default.htm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<li>
{% if image.title %}
<figure>
{% if __SELF__.imageResizerInstalled %}
{% if __SELF__.property('maxDimension') != 0 %}
<img title="{{image.title}}" src="{{image.path|resize(__SELF__.property('maxDimension'))}}" alt="">
{% else %}
<img title="{{image.title}}" src="{{image.path}}" alt="">
Expand All @@ -15,7 +15,7 @@
{% endif %}
</figure>
{% else %}
{% if __SELF__.imageResizerInstalled %}
{% if __SELF__.property('maxDimension') != 0 %}
<img src="{{image.path|resize(__SELF__.property('maxDimension'))}}" alt="">
{% else %}
<img src="{{image.path}}" alt="">
Expand Down
2 changes: 1 addition & 1 deletion lang/en/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
'slug' => 'Gallery slug',
'slugDescription' => '',
'maxDimension' => 'Max Dimension',
'maxDimensionDescription' => 'The length of the longest side of images if Image Resizer is installed'
'maxDimensionDescription' => 'The length of the longest side of images'
]
],
'galleriescomponent' =>[
Expand Down

0 comments on commit 23f7503

Please sign in to comment.