Let’s initiate a discussion!!
If you want to add watermark to the specific product image programmatically, then use below script.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
<?php /* * @ custom script to add watermark image on the product image that has -f in the product image name */ use Magento\Framework\App\Bootstrap; require __DIR__ . '/../app/bootstrap.php'; $bootstrap = Bootstrap::create(BP, $_SERVER); $objectManager = $bootstrap->getObjectManager(); $state = $objectManager->get('Magento\Framework\App\State'); $state->setAreaCode('frontend'); try { $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $categoryFactory = $objectManager->get('\Magento\Catalog\Model\CategoryFactory'); $category = $categoryFactory->create()->load(4); //Parent category /* * @ $cateid array of category IDs */ $cateid = $category->getAllChildren(true); // get all subcategory id $cateinstance = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\CollectionFactory'); $allcategoryproduct = $cateinstance->create()->addAttributeToSelect('*')->addCategoriesFilter(['in' => $cateid]); $fileSystem = $objectManager->create('\Magento\Framework\Filesystem'); $mediaPath = $fileSystem->getDirectoryRead(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA)->getAbsolutePath(); $productimages = array(); foreach ($allcategoryproduct as $products) { $product = $objectManager->create('Magento\Catalog\Model\Product')->load($products->getEntityId()); $productimages = $product->getMediaGalleryImages(); if(!empty($productimages)){ foreach($productimages as $productimage) { $imgname = substr(strrchr(rtrim($productimage['file'], '/'), '/'), 1); // Get specific image name if(strpos($imgname, '-f') !== false){ $fullpath = $mediaPath.'catalog/product'.$productimage['file']; if(file_exists($fullpath)){ watermark_image($fullpath, dirname(__FILE__)'/watermark-f.png', $fullpath); echo $productimage['file']."\n"; } } } } } } catch (\Exception $e) { echo $e->getMessage(); exit; } /* * @ watermark_image function for merge watermark image to the product image */ function watermark_image($target, $wtrmrk_file, $newcopy) { $watermark = imagecreatefrompng($wtrmrk_file); imagealphablending($watermark, false); imagesavealpha($watermark, true); $img = imagecreatefromjpeg($target); $img_w = imagesx($img); $img_h = imagesy($img); $wtrmrk_w = imagesx($watermark); $wtrmrk_h = imagesy($watermark); imagecopy($img, $watermark, $img_w - $wtrmrk_w, $img_h - $wtrmrk_h, 0, 0, $wtrmrk_w, $wtrmrk_h); imagejpeg($img, $newcopy, 100); imagedestroy($img); imagedestroy($watermark); } ?> |
[crayon-64216c0fc7a35073431295/] Using above fucntion Images can be imported directly from...
Override view block using di.xml and add the below code...
You can check a list of called layout XML for...
Follow the below steps to install and set up PWA...
If you want to remove all leading zero's from order,...
Let our Magento expert connect to discuss your requirement.
We offer Magento
certified developers.
Our Magento clientele
is 500+.
We sign NDA for the
security of your projects.
We’ve performed 100+
Magento migration projects.
Free quotation
on your project.
Three months warranty on
code developed by us.