Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Image Library
  • THanks, Ill try to replicate it later at my end
  • Right now I seem to be stuck with a bug in the GD library, which is adding a transparent PNG watermark to a transparent PNG ends up looking terrible. Here is a screenshot of it (http://i.gfxtub.com/a571cb.png). The black background was added to show the effect (Its actually a div with a black background with the image on top). So far I can't find a way around this, it works fine with images with no transparency with a transparent watermark. Code for that:
    $tmpimage = $this->create_transparent_image($wsizes->width, $wsizes->height);
    imagecopy($tmpimage, $image, 0, 0, $x, $y, $wsizes->width, $wsizes->height);
    imagecopy($tmpimage, $watermark, 0, 0, 0, 0, $wsizes->width, $wsizes->height);
    imagealphablending($image, false);
    imagecopymerge($image, $tmpimage, $x, $y, 0, 0, $wsizes->width, $wsizes->height, $this->config['watermark_alpha']);
    imagealphablending($image, true);
    

    For the presets, I wouldn't think of them as alternative configurations, though it is possible to do them that way. If I am understanding you correctly, your suggesting something like this:
    'default' => array(
        'name' => 'value',
        'name' => 'value',
        'name' => 'value'
    ),
    
    'other' => array(
        'name' => 'value',
        'name' => 'value',
        'name' => 'value'
    ),
    
    'another' => array(
        'name' => 'value',
        'name' => 'value',
        'name' => 'value'
    )
    

    Where default, other, and another are different configs. The only way I can think of doing that is to use something like Image::load_config to load a config, and Image::run_preset to run any actions in that config which would automatically load the config for that preset. Edit: huglester, for the save_pa function, it is possible but not needed. You could do that same thing with:
    array('resize_crop', 150, 150),
    array('save', 'prepend_text_$1_thumb_150x150_100')
    

    And call it with:
    Image::run_preset('thumbnail', 'filename_goes_here')
    

    Which would save it to prepend_text_file_name_goes_here_thumb_150x150_100. It would be easier with a save_pa function, so I'll add that :)
  • For anyone following along with this, the library is virtually done. Now I just need to add the new methods I added into the documentation, and fix one bug related to watermarks being larger than the image being watermarked in GD. Besides that I've tested it quite extensively, but if something does come up let me know. Also, if anyone can think of a better masking method for GD, that would be a nice improvement :)
  • Hello dudeami, well yeah, as you've said - it is possible, but could be easier.
    as for now I don't have any other thoughts.. So I am waiting for the
    first release to play with and see if there are any issues etc. And about the bug - I tried to google and not found any solution yet ..
    Maybe not all the hosts will have this problem? anyway -I think we
    will find the solution How are the things going? how is your hdd?:)
  • Everythings fine with the new HDD so far :) Anyways, I'll try and patch up as many GD related bugs as I can but I've had the same luck as you have. The only thing I can think of is to remove the transparency of the image before the watermark is added. Otherwise the imagemagick library will do it fine :) Right now I'm finishing up the GD functions and writing the imagemagick functions. Should be done soon hopefully :) The transparency issues with GD has caused a bit more work than I expected.
  • I'm waiting for news very much :) glad you have solved problems with HDD
    Anyway I find imagemagic a better image tool, since it accepts BMP's - which sometimes could make troubles
  • I ran into another problem. Some images don't get resized properly. I really can't see the system here, but all of the troublesome images where with a width pretty bigger than the height and were jpgs.
    Here's an example of an original http://www.cl.ly/460K042K2j003D1E1103 and then the resized thumb http://www.cl.ly/0C411i0N1v0S171X351w
    The thumb was produced with the following preset
    'actions' => array(
            array('crop_resize', 100, 100),
          )
    

    After it a second preset is used to generate a second thumb
    'actions' => array(
            array('resize', 200),
          )
    

    This second thumb is an empty jpg - 0kb.
    Another random image from the internet runs fine through the same process, producing proper thumbs. Here's the output that was in the log file, if it can be of any help:
    Error - 31.05.2011 22:14:49 --> 2 - imagecreatetruecolor(): Invalid image dimensions in ~/my_app/fuel/core/classes/image/gd.php on line 402
    Error - 31.05.2011 22:14:49 --> 2 - imagecolorallocatealpha() expects parameter 1 to be resource, boolean given in ~/my_app/fuel/core/classes/image/gd.php on line 374
    Error - 31.05.2011 22:14:49 --> 2 - imagesavealpha() expects parameter 1 to be resource, boolean given in ~/my_app/fuel/core/classes/image/gd.php on line 404
    Error - 31.05.2011 22:14:49 --> 2 - imagealphablending() expects parameter 1 to be resource, boolean given in ~/my_app/fuel/core/classes/image/gd.php on line 414
    Error - 31.05.2011 22:14:49 --> 2 - imagefilledrectangle() expects parameter 1 to be resource, boolean given in ~/my_app/fuel/core/classes/image/gd.php on line 415
    Error - 31.05.2011 22:14:49 --> 2 - imagealphablending() expects parameter 1 to be resource, boolean given in ~/my_app/fuel/core/classes/image/gd.php on line 416
    Error - 31.05.2011 22:14:49 --> 2 - imagecopyresampled() expects parameter 1 to be resource, boolean given in ~/my_app/fuel/core/classes/image/gd.php on line 80
    Error - 31.05.2011 22:14:49 --> 2 - imagejpeg() expects parameter 1 to be resource, boolean given in ~/my_app/fuel/core/classes/image/gd.php on line 299
    Error - 31.05.2011 22:14:49 --> 2 - imagedestroy() expects parameter 1 to be resource, boolean given in ~/my_app/fuel/core/classes/image/gd.php on line 30
  • Set debug to true in the config and post those results, and we can go from there.
  • Where should the output of the debug be?
  • It should just output in the page itself.
  • I put a die after the process and it then dumped this. Hope this is helpful. Image Class was initalized using the gd driver. Loaded ~/my_app/public/assets/logos/original_1.jpg with size of 1183x316
    Queued 'crop_resize', '100', '100' Saving image as ./assets/logos/50/original_1.jpg Executing 'crop_resize', '100', '100'
    Resizing image to 316, 85 with keeping AR and without padding.
    Cropping image 100x15+108+77 based on coords (108, 77), (208, 92)
    Reloading was called! Loaded ~/my_app/public/assets/logos/original_1.jpg with size of 1183x316 Loaded ~/my_app/public/assets/logos/original_1.jpg with size of 1183x316
    Queued 'resize', '200', NULL, true, false Saving image as ./assets/logos/200/original_1.jpg Executing 'resize', '200', NULL, true, false
    Resizing image to 0, 0 with keeping AR and without padding.
    Warning! ErrorException [ Warning ]: imagecreatetruecolor(): Invalid image dimensions COREPATH/classes/image/gd.php @ line 402: 401: {
    402: $image = imagecreatetruecolor($width, $height);
    403: $color = $this->create_color($image, null, 0);
    Warning! ErrorException [ Warning ]: imagecolorallocatealpha() expects parameter 1 to be resource, boolean given COREPATH/classes/image/gd.php @ line 374: 373: // Check if the transparency is allowed
    374: return imagecolorallocatealpha($image, $red, $green, $blue, $alpha);
    375: }
    Warning! ErrorException [ Warning ]: imagesavealpha() expects parameter 1 to be resource, boolean given COREPATH/classes/image/gd.php @ line 404: 403: $color = $this->create_color($image, null, 0);
    404: imagesavealpha($image, true);
    405: if ($this->image_extension == 'gif' || $this->image_extension == 'png')
    Warning! ErrorException [ Warning ]: imagealphablending() expects parameter 1 to be resource, boolean given COREPATH/classes/image/gd.php @ line 414: 413: // Set the blending mode to false, add the bgcolor, then switch it back.
    414: imagealphablending($image, false);
    415: imagefilledrectangle($image, 0, 0, $width, $height, $color);
    Warning! ErrorException [ Warning ]: imagefilledrectangle() expects parameter 1 to be resource, boolean given COREPATH/classes/image/gd.php @ line 415: 414: imagealphablending($image, false);
    415: imagefilledrectangle($image, 0, 0, $width, $height, $color);
    416: imagealphablending($image, true);
    Warning! ErrorException [ Warning ]: imagealphablending() expects parameter 1 to be resource, boolean given COREPATH/classes/image/gd.php @ line 416: 415: imagefilledrectangle($image, 0, 0, $width, $height, $color);
    416: imagealphablending($image, true);
    417:
    Warning! ErrorException [ Warning ]: imagecopyresampled() expects parameter 1 to be resource, boolean given COREPATH/classes/image/gd.php @ line 80: 79: $image = $this->create_transparent_image($cwidth, $cheight);
    80: call_user_func($this->gdresizefunc, $image, $this->image_data, $x, $y, 0, 0, $width, $height, $sizes->width, $sizes->height);
    81: $this->image_data = $image;
    Warning! ErrorException [ Warning ]: imagejpeg() expects parameter 1 to be resource, boolean given COREPATH/classes/image/gd.php @ line 299: 298:
    299: call_user_func_array('image'.$filetype, $vars);
    300: if ($this->config === false)
    Reloading was called!
    Warning! ErrorException [ Warning ]: imagedestroy() expects parameter 1 to be resource, boolean given COREPATH/classes/image/gd.php @ line 30: 29: if ( ! $return_data) {
    30: $this->image_data !== null and imagedestroy($this->image_data);
    31: $this->image_data = null; Loaded ~/my_app/public/assets/logos/original_1.jpg with size of 1183x316
  • Hmm... odd dimensions its coming up with, I'll look into it.
  • I've been trying desperately to make this class work for me. I am trying to extend the class to add two new methods. One method I am almost certain is not available in any form with GD. It is the gradient map effect as you would see in Photoshop (Imagemagick calls it color lookup table / -clut). I haven't been able to extend the Image class or even use the Imagemagick driver, at all, despite having Imagemagick installed and set in the Image config. I have tested to be positive Imagemagick is installed, via exec ( convert ... ); Can you help me understand how I should go about extending this class? Perhaps I am not able to extend this as I am other classes without drivers? And, if you would, do you understand why Fuel would reveal that GD is in use even though I have imagemagick set in both configs? E.g. Call to undefined method Fuel\Core\Image_Gd::gradientmap() app/classes/myimage.php
    <?php
    
    class MyImage extends Image &#123;
     
     public static function gradientmap()
     &#123;
      return 'bla';
     }
    }
    
    then, in my controller method, I call it
       MyImage::load($facebook_image_location."_original.jpg")
        ->gradientmap('#000000','#8dbfd5')
        ->output("jpeg");
    

    Edit: please excuse the html entities, I hope this will make sense to you even though parenthesis and opening braces have been converted and show as text..
  • For the extending, try extending the Image_Imagemagick class. The Image class is just for static use of the class, the Image_Driver, Image_GD, Image_Imagemagick, and Image_Imagick classes are where all the magic happens. Look at the drivers (fuel/core/classes/image/*) for how to make new methods. The drivers actually queue the commands, so you would need a gradientmap() function which queues the action, and a _gradientmap() which does the processing when save(), save_pa(), or output() is called. You can always modify the Image_Imagemagick class to add the gradientmap method and send a pull request, I bet others would like this feature. Also, post your config file and I'll try and help you get it working.
  • Thanks for your reply. I'll hack at it to try to make it work. I'm glad to see it would be worth of addition to the core! Hopefully I can get it to start working with the ImageMagick class.
  • Any clues on the resizing issues?
  • Hello dudeami! Wanted to ask how are the things going? You've probably met some more new bugs on the way to the finish line?:)
  • Hey, I haven't got around to it yet. Been getting a bit of work lately, I'll try to do the fixes sometime this weekend and send a pull request. Sorry for making you wait, shouldn't be too much longer.
  • Yeah, the GD library is starting to give me headaches :p. The imagemagick library is done for the most part, but I've been busy with school and a couple other things so working the bugs out haven't been my top priority. I'll try to get it up on github here shortly, even if its not completely done. I'd like to get this done soon, cause I plan on using it as well for my image upload site (Currently based on CI2). Anyways, I'll be sure to post here when its on github :) Sorry it's taking a bit longer than I thought >.<
  • No problem, I was just curious. Could you leave a reply here when the pull request is merged?
  • I'll leave a message here when I send it, then you can just take it from the repo or wait until its merged (They are usually quick with that)
  • Has anyone managed to get this working on wampserver? (version 2.1) using Windows 7. I get the following error messages: Error - 2011-04-23 23:28:50 --> 2 - imagealphablending() expects parameter 1 to be resource, null given in E:\projects\websites\fuelphp\fuel\fuel\core\classes\image\gd.php on line 466
    Error - 2011-04-23 23:28:50 --> 2 - imagecopy() expects parameter 2 to be resource, null given in E:\projects\websites\fuelphp\fuel\fuel\core\classes\image\gd.php on line 463 Here's my code: //config return array( 'presets' => array( 'mypreset' => array( 'bgcolor' => '#f00', // Set the background color red 'filetype' => 'jpg', // Output as jpeg. 'quality' => 75, 'actions' => array( array('crop_resize', 200, 200), array('watermark', '$1'), // Note the $1 is a variable. array('output', 'png') ) ) ) ); //controller Image::load('./a.jpg')->preset('mypreset', './watermark.gif'); [/] [code] //config
    return array(
    'presets' => array(
    'mypreset' => array(
    'bgcolor' => '#f00', // Set the background color red
    'filetype' => 'jpg', // Output as jpeg.
    'quality' => 75,
    'actions' => array(
    array('crop_resize', 200, 200),
    array('watermark', '$1'), // Note the $1 is a variable.
    array('output', 'png')
    )
    )
    )
    );
    //controller
    Image::load('./a.jpg')->preset('mypreset', './watermark.gif');
    [/]
  • Hello dudeami :) Long time no seen :)
    I thought maybe it won't be hard to implement smth like this?
    http://php.about.com/od/gdlibrary/ss/grayscale_gd.htm - so we could make color photos into greyscale in 1 easy step?:) Let me know what do you think about it .. Thanks :)
  • Hello, so far I've been testing this lib without any major problem..
    As for now I spotted one problem, using 'rounded' I get black corners instead of transparent .. Creating the thumbs, or crops is really easy and working nicely :) I'll post later more info on this, and maybe the controller, so anyone of you could get started faster!

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion