Yii Framework Forum: Working in a port of Image Component - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

Working in a port of Image Component Rate Topic: -----

#1 User is offline   Hwangar 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 39
  • Joined: 24-September 09
  • Location:Bilbao, Spain

Posted 29 September 2009 - 04:11 PM

Hi guys, I need image functionality (thumbs and so) and I'm currently porting one Drupal interface for working with GD2, making a component that interfaces to it with the aim to build an implementation for ImageMagick too in a while

My first design is to make a component with generic methods, an Interface for the implementations and one implementation for GD2, do you have comments? Am I in right direction?

As soon as I finish I'll publish something here

Greetings!
Hwangar
0

#2 User is offline   Hwangar 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 39
  • Joined: 24-September 09
  • Location:Bilbao, Spain

Posted 29 September 2009 - 04:34 PM

Ok, I'm finished :P

Here is the result (no testing yet, but as the code comes from Drupal I suppose it won't have too many mistakes), just to be placed in compoments directory and ready to use...

Please I want critics... above all about architecture, I'm beginning with all of this of Components and Behaviours and although I'm in my first steps, I'd like to contribute

Greetings,
Hwangar

Attached File(s)


0

#3 User is offline   Hwangar 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 39
  • Joined: 24-September 09
  • Location:Bilbao, Spain

Posted 30 September 2009 - 04:01 AM

ok, I'm sorry because yesterday it was late and what I uploaded was a bunch of untested code with many mistakes... today I'll upload the working version I use to build thumbnails using the strategy of "scale_and_crop" with the gd2 implementation... soon I'll try to upload the ImageMagic version

Greetings!
Hwangar
0

#4 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,788
  • Joined: 17-January 09
  • Location:Russia

Posted 30 September 2009 - 07:03 AM

Interesting thing. Are you going to create a google code project for it? Is ImageCache port planned?
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#5 User is offline   Hwangar 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 39
  • Joined: 24-September 09
  • Location:Bilbao, Spain

Posted 30 September 2009 - 09:20 AM

Hey samdark...

the thing is my first aim was to focus on ImageCache strategy but I quitted because of performance... as you know ImageCache follows the strategy of letting php serving the image (cached and modified) based on some configuration, and from my tests the Apache serving the modified file directly is 4 or 5 times faster than php dumping the same file cached, so first of all I'm porting the core lib in front of GD and ImageMagic and later I'll try to mount something like ImageCache

it's soon to mount a project, I'll try to send code for people to test, and later if the thing sounds interesting I'll make the project

Greetings!
Hwangar
0

#6 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,788
  • Joined: 17-January 09
  • Location:Russia

Posted 30 September 2009 - 10:41 AM

I think you've got it wrong that imagecache is serving images via php. Actually php is involved only in image resizing/filtering process that is triggered first time not yet existing image is requested. Resulting image is saved and then is serving directly without php. That's if you've configured Drupal to use "public" files mode instead of serving them with php.

Anyway, I'm interested in this project.
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#7 User is offline   Hwangar 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 39
  • Joined: 24-September 09
  • Location:Bilbao, Spain

Posted 30 September 2009 - 12:03 PM

noop...
If you dig in the code what ImageCache does is the next thing: imagine this url that seems to return an image:

http://localhost/dau...vo/P1020732.jpg

...files/imagecache... is a path attached to ImageCache that uses this code:
function imagecache_transfer($path) {
  $size = getimagesize($path);
  $headers = array('Content-Type: '. mime_header_encode($size['mime']));

  if ($fileinfo = stat($path)) {
    $headers[] = 'Content-Length: '. $fileinfo[7];
    _imagecache_cache_set_cache_headers($fileinfo, $headers);
  }
  file_transfer($path, $headers);
  exit;
}


to print in the buffer marking it as image/jpeg or whatever it is...

that's why I changed from Drupal to Yii, Drupal does a lot of things I want and I like but as a counterside, does even more I dont want at all, and for very custom webs, it's really slow, above all in my case I was using ImageCache intensively, drawing in one page more or less 40/50 images through its filter, and the result was reeeeaaaaally sloooooow

for this reason I'm planning (I have a prototype) a library that GENERATE a cache of files, but files are served directly by Apache (I dont want php serving'em)

Greetings
Hwangar
0

#8 User is offline   Hwangar 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 39
  • Joined: 24-September 09
  • Location:Bilbao, Spain

Posted 01 October 2009 - 04:38 AM

Ok, I learned a lot in "last day" and formatted the thing as a proper yii extension so... please test it!!!

With the advise of samdark I changed the focus more towards something like Drupal ImageChache

Instructions:
- Unpack the zip in extensions dir
- Add this to your config file:
 
   ...
    'image'=>array(
      'class'=>'ext.imageapi.CImage',
      'presets'=>array(
        'thumbs'=>array(
          'cacheIn'=>'webroot.imagecache',
          'actions'=>array(
            'scaleAndCrop'=>array('width'=>100, 'height'=>75),
            'rotate'=>array('degrees'=>30, 'background'=>0xff0000),
          ),
        )
      ),
    ),
    ...
    


Basic explanation: you can create as many presets as you want, in this case I have created one named "thumbs"
that caches files in the dir "webroot / imagecache", and for this preset I added two actions: scaleAndCrop and
later rotate. Currently (look at the code) I support: resize, scale, scaleAndCrop, rotate and crop

- For testing: create a controller and add for example this action:
  public function actionFile() {
    $thumb = Yii::app()->image->createUrl(
                'thumbs', // the preset we have configurated
                YiiBase::getPathOfAlias('webroot.files').'/X TRILE1.JPG'); // An image file!!!
    if ($thumb) print '<img src="'.$thumb.'" alt=""/>';
    else print "bad";
  }


- Invoke your action:
first time, the api will create the image and caches in the specified dir
rest, simply returns the cached images so... it's very fast

- Pendant things:
- api for purgue the cached images
- do as many actions as Drupal ImageCache???? :P
- open a serious project instead of a forum post

Thx!
Hwangar

Attached File(s)


0

#9 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,788
  • Joined: 17-January 09
  • Location:Russia

Posted 01 October 2009 - 06:24 AM

Will try today/tomorrow.
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#10 User is offline   Hwangar 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 39
  • Joined: 24-September 09
  • Location:Bilbao, Spain

Posted 02 October 2009 - 03:47 AM

Ok, I've created the extension for my initial release in Yii extensions page

I'm using it in a small project just to generate all kind of scaleAndCrop thumbs, and at the moment I have no complains... :lol:

Enjoy!
Hwangar
0

#11 User is offline   mech7 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 220
  • Joined: 26-March 09

Posted 03 October 2009 - 08:46 AM

http://phpthumb.gxdlabs.com/

Is pretty easy to use also... you can just drop it in the vendor dir
0

#12 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,788
  • Joined: 17-January 09
  • Location:Russia

Posted 03 October 2009 - 04:49 PM

phpthumb looks ok but it's much more like ImageAPI, not ImageCache.

Also there are two issues:
— No imagick support yet.
— Configuration is made by editing library source file.
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#13 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,788
  • Joined: 17-January 09
  • Location:Russia

Posted 03 October 2009 - 04:52 PM

Documentation page here is a bit messy.
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#14 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,788
  • Joined: 17-January 09
  • Location:Russia

Posted 03 October 2009 - 05:22 PM

What can be improved:
1. Use preset name to form target path to save images like it's done in Drupal. It will allow to have two and more thumbnails for the same named image.
2. Current method and properties names are a bit confusing.
3. How can I regenerate already generated image?
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#15 User is offline   Hwangar 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 39
  • Joined: 24-September 09
  • Location:Bilbao, Spain

Posted 05 October 2009 - 02:40 AM

thx to both for your comments... I'll take a time to improve the library and after thinking the weekend (spent the whole sunday with a big hangover because of that :P ), I'll implement the three ways to access the component:
  • tradicional library: that is calling the methods, as any class lib
  • defining presets at app config and calling for createUrl/Path giving the preset and putting the result image in an img tag, in that definition will come the operations over the image, the path to save them, etc
  • as samdark asked, I'll implement the ImageCache strategy, programming an Action that based on some parameter (preset) will return the image with the preset applied


on the other hand, I'll implement ImageMagik and of course "purgue" for the caches, lastly, I'll add more operations for using with presets

anyway... keep in mind that this is a first release so... be patient! (and thanks for testing)
Greetings
Hwangar
0

#16 User is offline   formoda 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 26-March 10

Posted 26 March 2010 - 07:23 AM

Hey, nice work :)

It'd be great to see the functionality from the Drupal module imagecache_actions too - it has some nice extras such as watermarking, text overlays etc.

Cheers,

Richard
0

#17 User is offline   Thomas Jensen 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 150
  • Joined: 01-August 09

Posted 03 May 2010 - 12:57 PM

I've added a function:
public function createAbsoluteUrl($presetName, $file) {
	return Yii::app()->getRequest()->getHostInfo().$this->createUrl($presetName, $file);
}

I used it in a RSS feed.
0

#18 User is offline   nuxtech 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 23
  • Joined: 23-October 10

Posted 18 September 2011 - 08:48 AM

it's very nice extension.
buat i've an error from runtime.
the message is like this

2011/09/18 15:40:11 [error] [php] imagecolorsforindex() [<a href='function.imagecolorsforindex'>function.imagecolorsforindex</a>]: Color index 99 out of range (C:\xampp\htdocs\protected\extensions\imageapi\GDToolkit.php:106)

i want to know, how it happen.
and how can i fixed it.
thanks
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users