Skip to content

Instantly share code, notes, and snippets.

@Kaapiii
Created July 20, 2017 15:21
Show Gist options
  • Save Kaapiii/d8edfad2e8b759b115f883a05503c6ed to your computer and use it in GitHub Desktop.
Save Kaapiii/d8edfad2e8b759b115f883a05503c6ed to your computer and use it in GitHub Desktop.
Concrete5 - Add thumbnail types programmatically
<?php
// Tested with Concrete5 version 8.2.0
$type = \Concrete\Core\File\Image\Thumbnail\Type\Type::getByHandle('custom_100x100px');
if(!is_object($type)){
$typeEntity = new \Concrete\Core\Entity\File\Image\Thumbnail\Type\Type();
$width = 100; // px
$height = 100; // px || null for auto
if ($height > 0) {
$typeEntity->setHeight($height);
}
if ($width > 0) {
$typeEntity->setWidth($width);
}
$typeEntity->setName('Thumb 100 x 100 px');
$typeEntity->setHandle('custom_100x100px');
$typeEntity->setSizingMode('proportional'); // values: proportional, exact
$typeEntity->save();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment