PHPackages                             shambix/wp-imager - 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. shambix/wp-imager

ActiveWordpress-library

shambix/wp-imager
=================

Image resizing and caching for WordPress, for theme developers. Supports Jetpack Photon.

1281PHP

Since Nov 18Pushed 6y ago2 watchersCompare

[ Source](https://github.com/Jany-M/wp-imager)[ Packagist](https://packagist.org/packages/shambix/wp-imager)[ RSS](/packages/shambix-wp-imager/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (1)Used By (0)

WP Imager `v 2.7.4`
===================

[](#wp-imager-v-274)

**WP Imager** makes image management easier when it comes to manipulating, caching and customizing WordPress images. It has a pure PHP WP twin, [PHP-Imager](https://github.com/Jany-M/php-imager)

Can be used inside or outside the loop:

- If used inside a loop, the script will automatically retrieve an image from the post, following a priority pattern: featured image, random image attached to the post, first image found in post even if external or not attached to post.
- If used outside the loop, for any image you want display in the template, use the `$exturl` param.
- If used outside the loop, to display images based on the Post ID, then use the param `$post_id`.

> Uses **[TimThumb](http://code.google.com/p/timthumb/)** for image resizing and caching

> **[WPML](https://wpml.org/)** 100% compatible

> Supports **WordPress [Jetpack](http://jetpack.me/)'s [Photon](https://developer.wordpress.com/docs/photon/api/) module**, it automatically switches to Photon cached images' URLs, if module is on, while keeping your custom sizes and with no need to tweak or edit a thing

> Caches images outside of the WordPress folders, to avoid clutter and overflowing upload folders

To-Do
-----

[](#to-do)

- Convert function params to array
- Add TimThumb filters
- Support for [Jetpack](http://jetpack.me/)'s [Photon](https://developer.wordpress.com/docs/photon/api/) filters. Maybe?

Requirements
------------

[](#requirements)

- PHP 5.2.x or higher
- GD image library

Get started
-----------

[](#get-started)

1. Place the provided `cache_img` folder in your site's root folder.

> Make sure that `cache_img/cache` is writable, in case images are not displaying.

2. Place the `wp-imager.php` file in your WP template.
3. Call `wp-imager.php` from your functions.php

```

```

> If you want to have pretty img urls, then there's an extra step:
>
> - If you don't have an `.htaccess` yet, place the one provided in your site's root folder.
> - If you already have an `.htaccess`, then adapt it, following the one provided.

**If you don't complete every step the script won't work.**

Parameters
----------

[](#parameters)

```

```

  Parameter Type Description &amp; Options Default   `width` int Resize dimension of width (dont put 'px' after size) 100   `height` int Resize dimension of height (dont put 'px' after size) 100   `crop` int Type of cropping to perform 0 = Resize to Fit exactly specified dimensions (no cropping) 1 = Crop and resize to best fit the dimensions (default) 2 = Resize proportionally to fit entire image into specified dimensions, and add borders if required 3 = Resize proportionally adjusting size of scaled image so there are no borders gaps 1   `class` string class name/names to append to image NULL   `link` bool Wraps the image in HTML, pointing to the image's post, with title attribute filled with post's title for better SEO. Won't work with `$exturl` false   `exturl` string URL of some external/custom image (eg. )  NULL   `nohtml` bool When false, image is wrapped in its `img` HTML tag, with `alt` attribute filled with post's title for better SEO. If true, only the image url is returned false   `post_id` int If empty, will retrieve `$post->ID` from active loop, else specify the post ID you need to retrieve the img from `$post->ID`   `bg_color` int When using crop value '2' (with borders) you can customize the borders color (the canvas beneath the image). ffffff Defaults
--------

[](#defaults)

- Function always returns to avoid yet another parameter, so simply echo it in your code.
- Processed IMG's quality is always 100
- Caching is done in a cache\_img folder, in the root of your website (provided)
- Pretty img urls are enabled by default. Adapt the .htaccess provided with the script.

### Usage

[](#usage)

Resize + default Cropping
-------------------------

[](#resize--default-cropping)

```

```

Resize with no Cropping
-----------------------

[](#resize-with-no-cropping)

```

```

Resize + default Cropping + Image Class
---------------------------------------

[](#resize--default-cropping--image-class)

```
