Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $halfPath='./media/catalog/product';
- $user="username"; //username for SOAPv2 api
- $pass="password"; //password for above user
- $products = array(20,21,22); //array of product IDs to be converted
- ini_set('display_errors',E_ALL);
- error_reporting(E_ALL);
- define('MAGENTO_ROOT', getcwd());
- $mageFilename = MAGENTO_ROOT . '/app/Mage.php';
- require_once $mageFilename;
- Mage::app();
- $baseurl=Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
- $client = new SoapClient($baseurl.'api/v2_soap/?wsdl');
- $sessionId = $client->login($user,$pass);
- $mediaApi = Mage::getModel("catalog/product_attribute_media_api");
- function kariobhai($jagah)
- {
- global $halfPath;
- $input = imagecreatefrompng($halfPath.$jagah);
- $width=imagesx($input);
- $height=imagesy($input);
- $output = imagecreatetruecolor($width, $height);
- $white = imagecolorallocate($output, 255, 255, 255);
- imagefilledrectangle($output, 0, 0, $width, $height, $white);
- imagecopy($output, $input, 0, 0, 0, 0, $width, $height);
- ob_start();
- imagejpeg($output);
- $img_content = ob_get_clean();
- imagedestroy($output);
- return base64_encode($img_content);
- }
- foreach($products as $prodID){
- $items = $mediaApi->items($prodID);
- foreach($items as $item) {
- if(substr($item['file'],-3)=='png'){
- $direction=kariobhai($item['file']);
- $str = preg_replace('/.*\/(.*?)\.png$/','$1', $item['file']);
- $newFile = array(
- 'name'=>$str,
- 'content' => $direction,
- 'mime' => 'image/jpeg'
- );
- $result = $client->catalogProductAttributeMediaCreate(
- $sessionId,
- $prodID,
- array( 'file'=>$newFile,'label' => $item['label'], 'position' => $item['position'], 'types' => $item['type'], 'exclude' => $item['exclude'])
- );
- if($result) $client->catalogProductAttributeMediaRemove($sessionId, $prodID, $item['file']);
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement