Image Helper create method

Permalink
I want to resize images to be viewed in an automatically generated slideshow. Trying to use the image helper with $im->create. I'm very confused on what the $newPath variable should be, which I think is why it has not worked for me. Can someone explain further how this method works and what values it accepts? (a directory to save the image to?/ should this directory already exist?/a full path with filename & extension?)

 
jordanlev replied on at Permalink Best Answer Reply
jordanlev
Don't use $im->create(), instead use $im->getThumbnail(). It will return a new object from which you can get the resized image info. For example:
<?php
$im = Loader::helper('image');
$full_img = File::getByID(123); //<--or however it is you're getting the images from the system
$maxWidth = 800; //or whatever
$maxHeight = 600; //or whatever
$img = $im->getThumbnail($full_img, $maxWidth, $maxHeight);
?>
<img src="<?php echo $img->src; ?>" width="<?php echo $img->width; ?>" height="<?php echo $img->height; ?>" alt="whatever" />
jlego replied on at Permalink Reply
I have tried that, but I already used the getThumbnail() method to create the actual thumbnails, and it does not seem to work. I also just felt it was more appropriate to create a new image because isn't it that concrete5 can only store 3 sizes from the getThumbnail() method?
jordanlev replied on at Permalink Reply
jordanlev
getThumbnail does create a new image. C5 can (and will) store as many images as you want with that function. It caches them and refers to them in the future when you request the image of the same size (so if you keep asking for 800x600, it won't keep recreating the same thumbnail over and over again, but if you ask it for 250x250, it will create a new one for you without affecting the other one that was 800x600 at all).

If you could post the code you're trying to use (I assume in the controller.php file of a block, or maybe in a theme template?), I could probably give you code that works for your situation.
jlego replied on at Permalink Reply
I just tried it again and it works this time. I've been building a pretty huge image-based block and i had tried it a while back when my php was probably invalid. Thank you for clarifying.
Just as a side note, what would be an appropriate situation to use $im->create()? Is there any place where it would be used instead of getThumbnail()?
jordanlev replied on at Permalink Reply
jordanlev
I can't think of a situation where you'd use $im->create() directly from a block or a theme. It's really just a utility function for the getThumbnail function.

-Jordan
ScottC replied on at Permalink Reply
ScottC
yeah but you can override those too in your config.php

From what i've seen clearing cache hasn't cleared the generated thumbnails, so once it is built it sticks around. We did this for a site for a lady that sold hats but her images were compressed, it took manually clearing the thumbnails out to create new ones without any of the compression artifacts.

define('AL_THUMBNAIL_WIDTH_LEVEL2', '500'); //or whatever
define('AL_THUMBNAIL_HEIGHT_LEVEL2', '500'); //likewise