[EXTENSION] Img


(Cniska) #1

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.


(Miguel Schpeir) #2

Hello Chris!

It seems like a HUGE job, Congratulations!

Can you post a demo please?


(Cniska) #3

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

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

Enjoy!


(Janez Dolinar) #4

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


(Cniska) #5

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.


(Cniska) #6

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!


(Jose Zdimera) #7

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?


(Jose Zdimera) #8

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.


(Cniska) #9

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.


(Africanbusinesszone) #10

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.


(E Haemastoma) #11

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?


(E Haemastoma) #12

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??


(Cniska) #13

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.


(E Haemastoma) #14

:wub:


(Cniska) #15

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!


(Rob Rhyne) #16

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.


(Rob Rhyne) #17

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!


(Rob Rhyne) #18

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.


(Alexey Naydenko) #19

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]


(Faz) #20

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