1
0
mirror of https://github.com/mosbth/cimage.git synced 2025-01-18 03:28:16 +01:00
php-cimage/README.md

105 lines
2.9 KiB
Markdown
Raw Normal View History

2012-04-25 15:49:09 +02:00
Image conversion on the fly using PHP
=====================================
2012-10-02 22:57:05 +02:00
About
-------------------------------------
2012-10-02 23:40:32 +02:00
The `CImage.php` is a PHP class that can resize and crop images on the fly on the server side
and output them to, for example to a webpage. The class preserves a cache of the generated
images and responds with HTTP 304 (not modified) if the image has not changed.
2012-04-25 15:49:09 +02:00
The file `img.php` uses `CImage.php` to resize images. It is a usecase on how to use
2012-10-02 22:49:43 +02:00
the class. `img.php` is useful for webpages which want to dynamically resize the images.
2012-04-25 15:49:09 +02:00
2012-10-02 22:49:43 +02:00
The file `test.php` has testcases that show the results of `img.php` with different
2012-04-25 15:49:09 +02:00
settings.
2012-10-02 22:57:05 +02:00
Start by reviewing the `test.php`, then have a look at `img.php` and finally go through
`CImage.php`.
2012-04-25 15:49:09 +02:00
2012-10-02 22:57:05 +02:00
CImage lives at github: https://github.com/mosbth/cimage
2012-10-02 22:49:43 +02:00
2012-10-02 23:25:03 +02:00
You can try out a live example at: http://dbwebb.se/kod-exempel/cimage/
2012-10-02 22:49:43 +02:00
Enjoy!
2012-04-25 15:49:09 +02:00
2012-10-02 23:00:39 +02:00
Mikael Roos (me@mikaelroos.se)
2012-04-25 15:49:09 +02:00
2012-10-02 22:57:05 +02:00
Installation
-------------------------------------
2012-10-02 23:25:03 +02:00
1. Clone from github: `git://github.com/mosbth/cimage.git`
2012-10-02 22:57:05 +02:00
2. Make the cache directory writable by the webserver.
2012-10-02 22:59:14 +02:00
<pre><code>
chmod 777 cache
</code></pre>
2012-10-02 22:57:05 +02:00
3. Point your browser to `test.php`.
2012-10-02 23:25:03 +02:00
4. Review the settings in `img.php` and try it out.
5. Advanced usage. Put `img.php` in your `/img`-directory. Create a `.htaccess` in your
2012-10-02 22:57:05 +02:00
web root folder containing the following line:
2012-10-02 23:00:39 +02:00
<pre><code>
RewriteEngine on
RewriteRule ^image/(.*)$ img/img.php?src=$1 [QSA,NC,L]
</code></pre>
2012-10-02 22:57:05 +02:00
Now you can access and resize your images through `/image/someimage.jpg?w=80`. Very handy.
2012-04-25 15:49:09 +02:00
Revision history
2012-10-02 22:57:05 +02:00
-------------------------------------
2012-04-25 15:49:09 +02:00
ToDo.
2012-10-02 22:57:05 +02:00
* Improved support for pre-defined sizes.
2012-10-02 22:49:43 +02:00
* crop-to-fit, add parameter for offset x and y to enable to define which area is the
center of the image from which the crop is done.
2012-10-02 22:57:05 +02:00
* Show how to integrate with WordPress, shortcodes.
* Support for resizing opaque images.
2012-10-02 23:25:03 +02:00
* Clean up code in `CImage.php`.
* Better errorhandling for invalid dimensions.
* Crop-to-fit does not work.
2012-10-02 22:49:43 +02:00
2012-10-02 23:40:32 +02:00
v0.3x (latest)
2012-10-02 23:40:32 +02:00
* Corrected error on naming cache-files using subdir.
* Corrected calculation error on width & height for crop-to-fit.
2012-10-02 23:40:32 +02:00
2012-10-02 22:57:05 +02:00
v0.3 (2012-10-02)
2012-10-02 22:49:43 +02:00
* Added crop. Can crop a area (`width`, `height`, `start_x`, `start_y`) from the original
image.
* Corrected to make the 304 Not Modified header work.
2012-10-02 22:57:05 +02:00
* Pre-defined sizes can be configured for width in `img.php`.
* Corrected to make crop work with width or height in combination with crop-to-fit.
2012-10-02 23:40:32 +02:00
2012-10-02 22:49:43 +02:00
v0.2 (2012-05-09)
* Implemented filters as in http://php.net/manual/en/function.imagefilter.php
2012-10-02 22:49:43 +02:00
* Changed `crop` to `crop_to_fit`, works the same way.
* Changed arguments and sends them in array.
* Added quality-setting.
* Added testcases for above.
2012-10-02 23:40:32 +02:00
v0.1.1 (2012-04-27)
* Corrected calculation where both width and height were set.
2012-04-25 15:49:09 +02:00
v0.1 (2012-04-25)
* Initial release after rewriting some older code I had lying around.
2012-10-02 22:49:43 +02:00
.
..: Copyright 2012 by Mikael Roos (me@mikaelroos.se)