Well, that's just how I would do it. If the other way works, and it's
less work for you, then there's no need to change it. It's just
natural for me to use RequestHandler since on most sites I already
have it loaded for AJAX and RSS.

As to manipulating images with PHP... I've only minimal experience
with that. I guess it depends on which graphics library you're using.
You could try GD's imagecreatefromstring() (
http://us2.php.net/manual/en/function.imagecreatefromstring.php ).

On May 14, 10:51 am, Ed Propsner <crotchf...@gmail.com> wrote:
> Thanks Calvin, I'm still working on it trying to overcome other issues. I've
> discovered that manipulating dynamically generated images using "blob" as
> the base (original) image is next to impossible unless I'm missing something
> which is extremely likely considering I don't know beans about it besides
> the obvious (perhaps a tad more). I'm finding that I have to write the file
> into a temp dir (which I'd rather not do), perform the manipulations, then
> move into the db as blob. I was convinced I wouldn't need to do this and
> spent forever trying not to but I was unable to find a work around (although
> I got close). Using the temp dir is fine, I'm just stubborn :) (if you have
> any ideas I'm all ears).
>
>  I didn't know any better when it came to Router::url, all I know is it
> worked an that was fine for the time being (have a lot to learn with Cake).
>
> Router::parseExtensions() and $RequestHandler->setContent seem like they
> will come in handy, I haven't looked into them yet. Even with pouring
> through the API countless times there is just so much more available that I
> was never aware of. Seems that most things really are a piece of "cake" as
> long as your work with it instead of against it. Once I'm able to
> confidently move, manipulate, and display images without any issues I'll
> tweak everything to use "proper" conventions and clean up the mess some I'd
> do it now but I'm already waist deep in this and it would feel a lot like
> starting over :)
>
> I not sure why I was using $html->tag instead of $html->image in this
> instance ... I do remember having issues in one area or another using 'blob'
> with it but i can't remember what exactly at the moment. I do need to take
> your advice though because $html->tag is becoming my new bad habit with
> cake. When in doubt, it works with almost everything.
>
> I'll be starting to implement your suggestions later today so I'm sure I'll
> more questions then.
>
> - Ed
>
> On Fri, May 14, 2010 at 1:05 PM, calvin <cal...@rottenrecords.com> wrote:
> > Wow, that was not nearly as well-formatted as I had hoped. Hope it's
> > still comprehensible. In any case, the import parts are simply:
> > 1. use Router::parseExtensions() to parse image extensions and pass
> > them to $RequestHandler (perhaps define the extensions array as a
> > model property to maintain DRY);
> > 2. use $RequestHandler->setContent() to set the content-types for the
> > various extensions
> > 3. and I forgot to mention this in the previous post, but copy the
> > ajax layout to /app/views/layout/image/default.ctp, and set $this-
> > >layout = 'image' in the controller action;
> > 4. create simple pass-thru view(s) (since they're all the same, you
> > could just use something like $this->render('image') instead of
> > Router::parseExtensions()'s default view locations);
> > 5. use $html->image instead of $html->tag; it will accept both strings
> > and arrays as image locations.
>
> > On May 14, 8:57 am, calvin <cal...@rottenrecords.com> wrote:
> > > Maybe I'm missing something here, but why is Router:url even needed?
> > > The only thing you needed to do was to switch the layout to one
> > > appropriate for displaying binary data (e.g. a blank layout like ajax)
> > > and set debug to 0 to suppress the SQL output. All of this could have
> > > been done by the RequestHandler component, e.g.:
>
> > > /**
> > >  * In /app/config/routes.php:
> > >  */
> > > Router::parseExtensions('png', 'jpg', 'jpeg', 'svg');
>
> > > /**
> > >  * In AppController:
> > >  */
> > > var $components = array('RequestHandler');
>
> > > /**
> > >  * In AppController->beforeFilter():
> > >  */
> > > $this->RequestHandler->setContent('png', 'image/png');
> > > $this->RequestHandler->setContent('jpg', 'image/jpeg');
> > > $this->RequestHandler->setContent('jpeg', 'image/jpeg');
> > > $this->RequestHandler->setContent('svg', 'image/svg+xml');
>
> > > /**
> > >  * In ImagesController->view():
> > >  */
> > > $ext = $this->RequestHandler->ext;
> > > $exts = array('png', 'jpg', 'jpeg', 'svg');
> > > if(in_array($ext, $exts)){
> > >     $filename = "$id.$ext";
> > >     $image = $this->Image->findByFilename($filename);} else {
>
> > >     // regular view action
> > >     if (!$id) {
> > >         $this->Session->setFlash(sprintf(__('Invalid %s', true),
> > > 'image'));
> > >         $this->redirect(array('action' => 'index'));
> > >     }
> > >     $image = $this->Image->read(null, $id);}
>
> > > $this->set(compact('image'));
> > > /**
> > >  * Create (or just create one and make the rest symbolic links):
> > >  * /app/views/images/png/view.ctp
> > >  * /app/views/images/jpg/view.ctp
> > >  * /app/views/images/jpeg/view.ctp
> > >  * /app/views/images/svg/view.ctp
> > >  * with:
> > >  */
> > > echo $image['blob_file'];
>
> > > /**
> > >  * To display an image on a page, just use:
> > >  */
> > > echo $html->image('/images/view/'.$userInfo['Photo'][0]['filename'],
> > > array('alt' => $userInfo['Photo'][0]['caption']))?>
> > > // $html->image() also takes arrays as the image path; no need for
> > > Router::url(), which, by the way, you can also call simply by $this-
>
> > > >url().
>
> > > Though, I think the media view should have a way of outputting files
> > > from the database or binary data directly passed to it.
>
> > > On May 12, 9:42 pm, Ed Propsner <crotchf...@gmail.com> wrote:
>
> > > > Thanks Martin, it worked just fine.
>
> > > > It turns out that with all I have tried I was actually close.
>
> > > > $this->layout = 'ajax'
> > > > AND
> > > > Router::url
>
> > > > made all the difference in the world.
>
> > > > I nearly fell out of my chair when the image displayed :)
>
> > > > - Ed
>
> > > > On Wed, May 12, 2010 at 11:54 PM, Martin Radosta <
> > martinrado...@gmail.com>wrote:
>
> > > > >  An approach
>
> > > > > in the controller:
>
> > > > > function show_image($recordId) {
> > > > >     $this->set('data', $this->Model->findById($recordId));
> > > > >     $this->layout = 'ajax'
> > > > > }
>
> > > > > the view show_image.ctp:
>
> > > > > Configure::write('debug', 0);
> > > > > header("Content-type: image/jpeg"); //assume jpg image
> > > > > echo $data['Model']['blob_file'];
>
> > > > > your view:
>
> > > > > echo $html->tag('img', array(
> > > > >     'src' => Router::url(array('controller' => 'your_controller',
> > 'action'
> > > > > => 'show_image', $userInfo['Photo'][0]['id']))
> > > > >     )
> > > > > );
>
> > > > > Regards
>
> > > > > MARTIN
>
> > > > > On 05/13/2010 12:26 AM, Ed Propsner wrote:
>
> > > > > Besides the size there should be no diff between "binary" and "blob",
> > I was
> > > > > just thinking that perhaps Cake handled them differently.
> > > > > I played around with media view and it doesn't seem to be what I'm
> > looking
> > > > > for.
>
> > > > >  I have it narrowed down to the headers and I can get the photo to
> > display
> > > > > but it has to be in it's own view and even then I have to echo the
> > image
> > > > > directly in the controller action ... this isn't working for me. I
> > never
> > > > > usually store photos directly to the database but in this instance i
> > feel it
> > > > > better serves my purpose without taking a hit on performance.
>
> > > > >  Ideally I would like to access the image through it's $hasMany assoc
> > and
> > > > > nest it in an image tag but I'm at a loss for how to pull that off
> > with
> > > > > Cake.
>
> > > > > On Wed, May 12, 2010 at 3:12 PM, Ed Propsner <crotchf...@gmail.com>
> > wrote:
>
> > > > >> I've been toying with this one for a while now and I'm not really
> > getting
> > > > >> anywhere.
>
> > > > >>  I'm trying to display a photo stored in db as type "blob". With
> > > > >> conventional PHP I would normally store the photo with type "binary"
> > and
> > > > >> never had any issues ... Blob is not going so well.
> > > > >> I figure the problem has something to do with content type but MVC
> > is
> > > > >> confusing me a bit when it comes to headers or media views. It seems
> > > > >> straightforward enough but I think I'm going about the wrong way
> > (I'm not
> > > > >> using media view or headers at this point).
>
> > > > >>  In my Users Model I set up a $hasMany assoc.
>
> > > > >>   var $hasMany = array(
> > > > >>         'Photo' => array(
> > > > >>             'className'     => 'Photo',
> > > > >>             'foreignKey'    => 'user_id',
> > > > >>             'conditions'    => array('Photo.profile' => 1,
> > 'Photo.private'
> > > > >> => 0),
> > > > >>             'limit'        => '1',
> > > > >>             'dependent'=> true
> > > > >>         )
> > > > >>     );
>
> > > > >>  Rendering the photo is the problem.
>
> > > > >>  > View
>
> > > > >>  $html->tag('img', array(
> > > > >>                                   'src' =>
> > $userInfo['Photo'][0]['file']
> > > > >>                                  )
> > > > >>                 )
>
> > > > >>  the "file" part of the array is empty:
>
> > > > >>   [Photo] => Array
> > > > >>         (
> > > > >>             [0] => Array
> > > > >>                 (
> > > > >>                     [file] =>
> > > > >>                     [user_id] => 1
> > > > >>                 )
>
> > > > >>         )
>
> > > > >>  I tried a lot of different things but nothing worked the way I
> > want.
> > > > >> What is the proper way to go about this?
>
> > > > >>  - Ed
>
> > > > >  Check out the new CakePHP Questions sitehttp://cakeqs.organdhelp
> > > > > others with their CakePHP related questions.
>
> > > > > You received this message because you are subscribed to the Google
> > Groups
> > > > > "CakePHP" group.
> > > > > To post to this group, send email to cake-php@googlegroups.com
> > > > > To unsubscribe from this group, send email to
> > > > > cake-php+unsubscr...@googlegroups.com<cake-php%2bunsubscr...@googlegroups.com>For
> > > > >  more options, visit this group
> > > > > athttp://groups.google.com/group/cake-php?hl=en
>
> > > > >  Check out the new CakePHP Questions sitehttp://cakeqs.organdhelp
> > > > > others with their CakePHP related
>
> ...
>
> read more »

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to