PHPackages                             mitogh/katana - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Search &amp; Filtering](/categories/search)
4. /
5. mitogh/katana

ActiveLibrary[Search &amp; Filtering](/categories/search)

mitogh/katana
=============

Filters to control where the size of images are generated.

2.0.0(10y ago)204.4k[2 issues](https://github.com/mitogh/katana/issues)PHPPHP &gt;=5.3.0

Since Oct 16Pushed 10y ago3 watchersCompare

[ Source](https://github.com/mitogh/katana)[ Packagist](https://packagist.org/packages/mitogh/katana)[ Docs](https://github.com/mitogh/Katana)[ RSS](/packages/mitogh-katana/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)Dependencies (3)Versions (6)Used By (0)

Katana [![Build Status](https://camo.githubusercontent.com/f2be4e014c4c06b3ae6b6ffd13271af5301305116326c49cbaeac64783a1d125/68747470733a2f2f7472617669732d63692e6f72672f6d69746f67682f4b6174616e612e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/mitogh/Katana)
=============================================================================================================================================================================================================================================================================

[](#katana-)

> Save disk space and creates custom images sizes only where is required.

Custom filters to make sure the image sizes are generated only on pages or posts that requires the sizes on [WordPress](https://wordpress.org/), this will help to save some disk space of images that are not used at all on your WordPress installation.

[![](/media/samurai.jpg)](/media/samurai.jpg)
Picture from [WikiImages](https://pixabay.com/samurai-guerrero-caza-de-samurai-67662/)

Previous version.
-----------------

[](#previous-version)

If you are using a version below 2, please make sure you take a look at [the previous docs](readme-1.md) and if you are going to upgrade make sure you follow the installation guide.

Installation
------------

[](#installation)

**This is not a plugin**, rather is a library that can be used with your own plugin or your theme.

1. You need to download the library using [composer](https://getcomposer.org/). In order to do this you can run the following command:

```
composer require mitogh/katana
```

This will add the latest version of the library on your installation and will create a vendor directory where the files are going to be located.

2. If you are using a plugin or `functions.php` from a theme you only need to include the following file:

```
include dirname( __FILE__ ) . '/vendor/autoload.php';
```

That will allow you to use any filter from the class from `Katana` or any other package installed via composer.

That's practically all the process you need to follow in order to install the library, since the library automatically creates the object that is used for create the post and page filters.

Usage
-----

[](#usage)

This library comes with some filters that allows you edit what sizes of images are generated under certain post types, page templates, post ID or any other custom conditional.

Default size
------------

[](#default-size)

As a note or reminder take into account that the default image size is always generated even if you remove all image sizes with the filters.

Filters
-------

[](#filters)

Each filter allow to return what sizes of images are needed for that particular filter, the returned sizes represents the allowed images sizes, each size is the name that was registered when you created an image size using `add_image_size`.

By default Katana applies 3 filters in the following order:

1. Filter by post\_id - priority 10
2. Filter by post type - priority 20
3. Filter by template page - priority 30

About filter priorities:

> Used to specify the order in which the functions associated with a particular action are executed. Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the filter.

So if you are creating your own filter make sure to take priorities into account.

### katana\_refine

[](#katana_refine)

This is the filter triggered by Katana and is the one that you can use to create custom conditionals or to create new filter names.

The filter sends two parameters, so you need to explicity specify the number of arguments that are send to the filter:

- `$sizes` An array with the sizes of the images availables on the site.
- `$id` The id of the post that triggers the filter.

For example you want to remove all the image sizes from a page that has the title `tomacco`

```
add_filer( 'katana_refine', function($sizes, $id) {
    $title = strtolower( get_the_title( $id ) );
    if ( $title === 'tomacco' ) {
      return [];
    } else {
      return $sizes;
    }
}, 10, 2);
```

### katana\_refine\_{post\_type}

[](#katana_refine_post_type)

`{post_type}`, can be any post type declared on the site, post page or even a custom one, like movies.

This filter allows to refine the sizes of images for a certain post type.

**Example**

This example remove all the sizes from all of the pages, so any time you add an image on a page it won't create a new size of image.

```
add_filter('katana_refine_page', '__return_empty_array');
```

The default two filters are:

- `katana_refine_post`: Will allow you to update all the images generated in all posts.
- `katana_refine_page`: Allow you to change the default sizes generated on all the pages.

Every time you create a new post type, you can use a new filter with the slug of the new post type.

### katana\_refine\_{post\_id}

[](#katana_refine_post_id)

`{post_id}`, is the id of the post, page or custom post type. (all new entries has a `post_id`)

This filter allows you to change the sizes on a particular `post_id`. (All posts, pages or custom post types has a post\_id, than can be used with this filter).

**Example**

Imagine we have previously declared an `author_profile_image` size of an image, as follows:

```
add_image_size( 'author_profile_image', 350, 350, true );
```

We need to creates images of the `author_profile_image` size only in the entry with the id: `105`.

```
add_filter('katana_refine_105', 'allow_only_author_profile_image');

function allow_only_author_profile_image( $sizes ){
  return array( 'author_profile_image' );
}
```

### katana\_refine\_{template\_slug}

[](#katana_refine_template_slug)

`{template_slug}`, is the slug of the template, the slug is where is located the template, the template name is generated only with the last name of the template and removing the `.php` extension of that template file, some examples below:

**Examples**

LocationFilter namepage-templates/full.phpkatana\_refine\_fullpage-templates/shop-page.phpkatana\_refine\_shop\_pageportfolio.phpkatana\_refine\_portfolio**Example**

This filter just allow to create two sizes of images in the `page-template/full.php`:

- poster
- landscape

```
add_filter('katana_refine_full', 'image_sizes_for_full_page_template');

function image_sizes_for_full_page_template( $sizes ){
  return array( 'poster', 'landscape' );
}
```

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~54 days

Total

4

Last Release

3704d ago

Major Versions

1.1.3 → 2.0.02016-03-27

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3921289?v=4)[Crisoforo Gaspar Hernández](/maintainers/mitogh)[@mitogh](https://github.com/mitogh)

---

Top Contributors

[![mitogh](https://avatars.githubusercontent.com/u/3921289?v=4)](https://github.com/mitogh "mitogh (108 commits)")

---

Tags

composerphpwordpresswordpress-imageswordpressfilterimages

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/mitogh-katana/health.svg)

```
[![Health](https://phpackages.com/badges/mitogh-katana/health.svg)](https://phpackages.com/packages/mitogh-katana)
```

###  Alternatives

[millat/laravel-hooks

The WordPress filter, action system in Laravel

5715.1k](/packages/millat-laravel-hooks)[dms/dms-filter-bundle

DMS Filter Bundle, makes Annotation based entity filtering available in Symfony

78351.6k1](/packages/dms-dms-filter-bundle)[silverstripe-terraformers/gridfield-rich-filter-header

Rich filter header component for GridField

1325.7k1](/packages/silverstripe-terraformers-gridfield-rich-filter-header)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
