[EXTENSION] Img

Hello All,

It’s been a while since I released my Rights module so I thought it was about time to give something new to the community. So, here it is, my newest module, Img.

Img is an image manager which allows for saving, loading, deleting and versioning of images in your Yii application. Images are stored both on the hard-drive and in the database. The module utilizes the PHPThumb library to provide a wide range of image transformation options.

Img comes with an installer so it’s very easy to set up and you should have it up and running in no time. Here’s a list of the features:

Features

  • Image management through one single application component.

  • Saving, loading and deleting of images easily

  • A wide variety of image transformation options

  • Active record for storing the image data

  • Installer for quick and easy set up

  • Extensive configuration options

The project can be found here:

http://www.yiiframework.com/extension/img/ or

Fork Img on Bitbucket:

https://bitbucket.org/Crisu83/yii-img

Installation

Installation instructions can now be found here:

http://www.yiiframework.com/extension/img/#hh2

Thank you for reading

I hope you will find the module useful for your projects.

Please leave your comments and/or questions below.

Hello Chris!

It seems like a HUGE job, Congratulations!

Can you post a demo please?

I’ve released Img version 1.0 and finally registered the extension on Yii:

http://www.yiiframework.com/extension/img/

Enjoy!

I’ll have a dip in it today. Just quick q: does it do watermarking?

Hey Tuksi,

I haven’t done watermarking with it but it should support it, if Google can be trusted that is.

Here’s a link you might find useful:

http://www.gen-x-design.com/projects/php-thumbnailer-class/

If you scroll down on the page you’ll find some code for watermarking.

Version 1.0.1 is now available.

The newest version can be downloaded here:

http://www.yiiframework.com/extension/img/files/yii-img-1.0.1.zip/

I changed the image extensions to be managed automatically.

Enjoy!

Hello, i am new to yii and oo programming in php. i tried to use your module with code you provided in reply to "bonnie" in the module description.

i am getting error [color="#FF0000"]The table "{{Image}}" for active record class "Image" cannot be found in the database.[/color]

it is raised in saveImage() method.

the table in my database exists (i did run the install script of your module). i use mysql. can there be a problem with the capitalized first letter of table name? or any hints where is the problem?

can you please help me?

i changed the tableName() method in your class Image to return ‘image’ instead of ‘{{Image}}’ and it works now. not sure if this is right i still do not understand the yii object concept entirely.

I’m not sure what the standard is but ‘{{Image}}’ works if you set you ‘db’-components ‘tablePrefix’ to “” (an empty string).

If there’s a standard please let me know and I’ll change it.

Hi, Chris this is Bonnie again. I tried using the module to upload and display the images as you said but I don’t see any file downloaded only my values for the auto listings. Also on the display the constant does not work. If you need I can post my code to see how am using it. I use CmultipleUpload widget for uploading. Thanks again. I really need help to get it working or if anybody has succeeded please help.

Hey Chris: I successfully installed and played with this last night – thanks.

I’m still pretty new to Yii and PHP, but I think your extension is really only set up for a single model?

What I was hoping to do was to use it across my whole application, so that it would manage:

[list=1]

[*]Product Images

[*]Avatars

[*]Product Category Images

[*]etc

[/list]

But to do that I’d think there would need to be a concept of the model in both the Db and file structure.

Is that something you’re planning to do with this extension?

Forget that question… I should have played a little longer: it all works as expected.

I’ve just added an issue on your G.code page though: do you think that the versions should be deleted when you delete the Db record?

Would you do that by overriding the CActiveRecord delete method??

Actually just found the answer: beforeDelete() is the right way isn’t it??

Hey scribbly,

The problem is actually that the module doesn’t implement support for deleting images at all. However, I recently added this functionality and it will be included in the next release.

:wub:

Version 1.0.2 is now available.

The newest version can be downloaded here:

http://www.yiiframework.com/extension/img/files/yii-img-1.0.2.zip/

I added functionality for deleting images.

I’m also considering switching to the phpthumb() library as it provides a lot more functionality and it’s being updated frequently.

Enjoy!

I had the same problem as josez, same fix temporarily helped me out as well after trying image and tbl_image and tbl_Image as well.

(my prefix is tbl_) If I’m not mistaken, the convention for table names is lowercase.

What is the best way to render images in views?

I simply dropped this in my view, where $data->image is the Image id I placed in my model.

<img src="/files/images/versions/small/<?=$data->image_id?>.jpg" />

Thanks!

Chris,

Thanks for your module. I’ve just gotten it to work fully and have some suggestions:

  1. saving a file name with just the id hurts the SEO value of the img file name

  2. speaking of SEO, alt and title might be good additions (though maybe out of scope for your project?)

  3. i’d love to see some type of easy rendering function that possibly worked with a lightbox type solution

Thanks again.

Hello Chris!

First a big thanks for you great extensions!

Second — big sorry for my English.

About this one I want to ask you about the next items:

[list=1][]As I understand you position this module as common way to manage all application images. If this is right, I want to ask about your willing to create some storing mechanism to distribute images files by different directories to avoid server loading when count is over ~1000 or more files in one directory.[]Maybe I did not figured how it works. What about caching created images? Will it always be recreated on each request?[*]Class ImgManager is declared as a child of CApplicationComponent, but in the ImgManager::init() method you don’t call parent::init(). Is this the same as should be?[/list]

Firstly great work on this!!

I’ve started to use this and I noticed that some of the image conversions were a bit low quality - so I amended the phpThumb library to start using ImageMagick (instead of GD). Unfortunately this does not seem to work; i’m using auto-resizing of images (when called).

Any idea why this is not working?

Thanks