Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

[solved] How to get an imgae object in own modul from imagename
 
bravehartk2
Member
 
Avatar
Total Posts:  34
Joined:  2008-08-14
 

Hi guys,
I´m looking for a way for getting an imageobject from an imagepath in my own modul. I can upload the image in my adminhtmlform and save the imgaename in the database. but now I need to load the Imgage as a imageobject like the productimages with resizefunctionality. But I dont now which model I can use!

Can somebody give me a hint?

Thanks:
Bravehartk2

 
Magento Community Magento Community
Magento Community
Magento Community
 
bravehartk2
Member
 
Avatar
Total Posts:  34
Joined:  2008-08-14
 

Nobody an Idea? Youst a Tip? Please I need help!

 
Magento Community Magento Community
Magento Community
Magento Community
 
bravehartk2
Member
 
Avatar
Total Posts:  34
Joined:  2008-08-14
 

Soooo I make it myself!

For any prospect, thats the way is works!

First you have to write a configuration class, that implements dthe interface Mage_Media_Model_Image_Config_Interface. In that class you can set the right paths to your images you have uploadet (f.e. via backendform).

Excample:

<?php

class MyNamespace_MyModul_Model_Image_Config implements Mage_Media_Model_Image_Config_Interface{
  
/**
     * Retrive base url for media files
     *
     * @return string
     */
    
public function getBaseMediaUrl(){
      
return Mage::getBaseUrl('media'). DS "MyFolder" DS ;
    
}

    
/**
     * Retrive base path for media files
     *
     * @return string
     */
    
public function getBaseMediaPath(){
      
return Mage::getBaseDir('media'). DS "MyFolder" DS ;
    
}

    
/**
     * Retrive url for media file
     *
     * @param string $file
     * @return string
     */
    
public function getMediaUrl($file){
      
return Mage::getBaseUrl('media'). DS "MyFolder" DS $file;
    
}

    
/**
     * Retrive file system path for media file
     *
     * @param string $file
     * @return string
     */
    
public function getMediaPath($file){
      
return Mage::getBaseDir('media'). DS "MyFolder" DS $file;
    
}
}

Now you can do the trick where you need it:

//creating an Image

//-> Instanciate an own configuration
        $config Mage::getModel('mymodule/image_config');

        
$image Mage::getModel('media/image');

//-> set your configuration
        
$image->setConfig($config);
         

//-> get A link to a temparary image in the wanted dimension         
        
Output '<img src="'.$image->getSpecialLink("currentImageName",'50,50').'"/>';

Thats all! I hope it is understandable, because my englich isn´t the best!

Errors or Tips? Please post it here!

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top