title: Data Mappers, Models and Images
body: <p>I've seen and read plenty of blog posts and forum topics talking about and giving examples of Data Mapper / Model implementations in PHP, but I've not seen any that also deal with saving files/images.</p>
  
  <p>I'm currently working on a Zend Framework based project and I'm doing some image manipulation in the model (which is being passed a file path), and then I'm leaving it to the mapper to save that file to the appropriate location - is this common practise?</p>
  
  <p>But then, how do you deal with creating say 3 different size images from the one passed in? At the moment I have a <code>setImage($path_to_tmp_name)</code> which checks the image type, resizes and then saves back to the original filename. A call to <code>getImagePath()</code> then returns the current file path which the data mapper can use and then change with a call to <code>setImagePath($path)</code> once it's saved it to the appropriate location, say "/content/my_images". Does this sound practical to you?</p>
  
  <p>Also, how would you deal with getting the URL to that image? Do you see that as being something that the model should be providing? It seems to me like that model should worry about where the images are being stored or ultimately how they're accessed through a browser and so I'm inclined to put that in the ini file and just pass the URL prefix to the view through the controller. Does that sound reasonable?</p>
  
  <p>I'm using GD for image manipulation - not that that's of any relevance.</p>
  
  <p><strong>UPDATE:</strong> I've been wondering if the image resizing should be done in the model at all. The model could require that it's provided a "main" image and a "thumb" image, both of certain dimensions. I've thought about creating a <code>getImageSpecs()</code> function in the model that would return something that defines the required sizes, then a separate image manipulation class could carry out the resizing and (perhaps in the controller?) and just pass the final paths in to the model using something like <code>setImagePaths($images)</code>.</p>
  
  <p>Any thoughts much appreciated :)</p>