Skip to content

Instantly share code, notes, and snippets.

@gisu
Last active February 4, 2017 12:54
Show Gist options
  • Save gisu/c290495aecd9689fe8987e685a0f056d to your computer and use it in GitHub Desktop.
Save gisu/c290495aecd9689fe8987e685a0f056d to your computer and use it in GitHub Desktop.
Wordpress Image Generation and Handling
<?php
/**
Image Sizes
===========
Build a Set of different Imagesets
Part of your function.php
*/
// Uncopped Image Sizes
$UNCROPPED_SIZES = [
'large' => '1400',
'wide' => '1200',
'desktop' => '960',
'tablet' => '768',
'medium' => '480',
'small' => '320',
'micro' => '150'
];
// Cropped Image Sizes
$CROPPED_SIZES = [
'large' => '1200',
'medium' => '800',
'small' => '400',
'mini' => '100'
];
// Different Formats with different ratios (insert the Result of Ratio hight/width)
$CROPPED_FORMAT = [
'square' => '1', // 1:1
'wide' => '0.5625', // 16:9
'extrawide' => '0.4761', // 21:10
'rect' => '0.75' // 4:3
];
// Generate Uncropped Images
foreach ($UNCROPPED_SIZES as $key => $value) {
add_image_size('rw_'.$key, $value, 9999);
}
// Generate Crop Sets
foreach ($CROPPED_FORMAT as $type => $ratio) {
// Generate Crop Sizes
foreach ($CROPPED_SIZES as $key => $value) {
$height = $value * $ratio;
add_image_size($type.'_'.$key, $value, $height, true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment