Created
October 30, 2014 14:32
-
-
Save MikeWilkie/7f60f7a0e6f9b9f94058 to your computer and use it in GitHub Desktop.
Magento png to jpg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once '../app/Mage.php'; | |
umask(0); | |
Mage::app(''); | |
function dupeImage($path) { | |
$img = imagecreatefrompng($path); | |
$new = str_replace('.png','.jpg',$path); | |
$bg = imagecreatetruecolor(imagesx($img), imagesy($img)); | |
imagefill($bg, 0, 0, imagecolorallocate($bg, 255, 255, 255)); | |
imagealphablending($bg, TRUE); | |
imagecopy($bg, $img, 0, 0, 0, 0, imagesx($img), imagesy($img)); | |
$quality = 100; // 0 = worst / smaller file, 100 = better / bigger file | |
imagejpeg($bg, $new, $quality); | |
ImageDestroy($bg); | |
echo $new . "\n"; | |
} | |
$magePath = Mage::getBaseDir(); | |
$mediaPath = $magePath . '/media/catalog/product'; | |
$cachePath = $mediaPath . '/cache'; | |
$directory = new RecursiveDirectoryIterator($mediaPath,RecursiveDirectoryIterator::SKIP_DOTS); | |
$iterator = new RecursiveIteratorIterator($directory,RecursiveIteratorIterator::LEAVES_ONLY); | |
$extensions = array("png"); | |
foreach ($iterator as $fileinfo) { | |
if (in_array($fileinfo->getExtension(), $extensions)) { | |
if (strpos($fileinfo->getPathname(),$cachePath) !== true) { | |
$files[] = $fileinfo->getPathname(); | |
} | |
} | |
} | |
foreach ($files as $galleryImage){ | |
dupeImage($galleryImage); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment