Clemens,

Use $this->data['Picture']['File']['tmp_name'] as src, create a scaled
image file and use it to set up $this->data['Picture']. Here's the
function I use:

        private function scaleImage($srcpath, $args) {

                // cache functionality, no extra charge
                if (file_exists($args['filepath'])) {
                        return;
                }

                // create src image, depending on image_type
                switch ($args['image_type']) {
                        case IMAGETYPE_JPEG:
                                $srcimg = imagecreatefromjpeg($srcpath);
                                break;

                        case IMAGETYPE_GIF:
                                $srcimg = imagecreatefromgif($srcpath);
                                break;

                        case IMAGETYPE_PNG:
                                $srcimg = imagecreatefrompng($srcpath);
                                break;

                        default:
                                return;         // unknown type, so can't 
create new file
                }

                if ($srcimg === false) {
                        return;         // error reading src image
                }

                // create dst image
                $dstimg = imagecreatetruecolor($args['width'], $args['height']);
                if ($dstimg == null) {
                        imagedestroy($srcimg);
                        return;         // error creating dst image, so can't 
create new file
                }

                // copy image
                imagecopyresampled($dstimg, $srcimg, 0, 0, 0, 0,
                        $args['width'], $args['height'], $args['orig_width'], 
$args
['orig_height']);

                // save dst image, depending on image_type
                switch ($args['image_type']) {
                        case IMAGETYPE_JPEG:
                                imagejpeg($dstimg, $args['filepath'], 40);
                                break;

                        case IMAGETYPE_GIF:
                                imagegif($dstimg, $args['filepath']);
                                break;

                        case IMAGETYPE_PNG:
                                imagepng($dstimg, $args['filepath']);
                                break;

                        default:
                                break;          // can't happen--we switched on 
type earlier
                }

                // destroy both images, clean up
                imagedestroy($srcimg);
                imagedestroy($dstimg);

        }

On Jun 2, 2:26 am, "Clemens K." <[email protected]> wrote:
> hi.
>
> i can already upload pictures to my mysql database in blob format. i
> want to add an automatical resize when uploading. my code:
>
> $fileData = fread(fopen($this->data['Picture']['File']['tmp_name'], "r
> +"), $this->data['Picture']['File']['size']);
>
> $this->data['Picture']['name'] = $this->data['Picture']['File']
> ['name'];
> $this->data['Picture']['type'] = $this->data['Picture']['File']
> ['type'];
> $this->data['Picture']['size'] = $this->data['Picture']['File']
> ['size'];
> $this->data['Picture']['data'] = $fileData;
>
> $this->Picture->save($this->data);
>
> how can i implement a resize function now? does someone have any idea
> and some code? :)
>
> thanks and regards,
> clemens
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to