[Typo3-dev] scale images in extensions

Christopher bedlamhotel at gmail.com
Sat Dec 10 06:38:42 CET 2005


Hi,

On 09/12/05, Christoph Koehler <christoph.koehler at gmail.com> wrote:
> Hello list,
>
>
> how would I go about scaling an user uploaded images to certain dimensions?
> I will probably need it in thumbnail and one larger size. I looked at the
> t3lib_stdgraphics class but couldn't figure out how to use it. Is it as
> easy as setting dimensions for the picture in my template, or how should I
> scale, save and later retrieve user uploaded images?
>

You should have a look at the extension dev videos; there's a part
where Kasper does exactly this (including the option to resize it
using the extension's TS template).

Assuming you can figure out the path to the image, all you need to do
is treat the image exactly as you would in TS, except that you're
doing it in the php code. For example:

TS:

plugin.my_ext_pi1 {
  # Set preferences for the thumbnail image here:
  thumbnail = IMAGE
  thumbnail {
    # Add various IMAGE properties here (size, alt attribute etc...)
  }
}

php:

// Where is the current image going to be?
$path_to_image = '/path/to/image/';

// What's the file name of the current image?
$image_file_name = some_function_that_finds_image_files();

// Override the .file property of the IMAGE cobject in case it was defined
// in the TS:
$this->conf['thumbnail.']['file'] = $path_to_image . $image_file_name;

// Pass the combination of TS-defined values and php processing through
// the IMAGE cobject function:
$output = $this->cObj->IMAGE($this->conf['thumbnail.']);

// Return a value:
return $output;


...and that's basically it.


-Christopher




More information about the TYPO3-dev mailing list