magento 2.1 - 如何在 REST 中或从外部脚本中获取缓存图像缩略图的完整路径

magento 2.1 - How to get the full path of the cached image thumbnails in REST or from external script

magento 2.1 - 如何在 REST 中获取缓存图像缩略图的完整路径 API 调用

我知道图片在/pub/media/catalog/product/

我需要知道如何获取缓存版本:/pub/media/catalog/product/cache/thumbnail/140x140/beff4985b56e3afdbeabfc89641a4582/

有使用对象管理器的想法吗?

解决了,谁在找同样的问题。以下代码从加载 magento bootstrap 的外部脚本运行:

use Magento\Framework\App\Bootstrap;
require __DIR__ . '/../app/bootstrap.php';
$params = $_SERVER;
$bootstrap = Bootstrap::create(BP, $params);
$objectManager = $bootstrap->getObjectManager();

$appState = $objectManager->get('\Magento\Framework\App\State');
$appState->setAreaCode('frontend');

$storeManager = $objectManager->get('\Magento\Store\Model\StoreManagerInterface');
$appEmulation = $objectManager->get('\Magento\Store\Model\App\Emulation');
$imageFactory = $objectManager->get('\Magento\Catalog\Helper\ImageFactory');
$productRepository = $objectManager->get('\Magento\Catalog\Model\ProductRepository');
$storeId = $storeManager->getStore()->getId();

function getImageURL($pid, $attr=['width'=>500,'height'=>500,'watermarked'=>true,'imageId'=>'product_thumbnail_image'])
{
  global $imageFactory,$productRepository;
  $product = $productRepository->getById($pid);
  $image = $imageFactory->create()->init($product, $attr['imageId'])
      ->constrainOnly(true)
      ->keepAspectRatio(true)
      ->keepTransparency(true)
      ->keepFrame(true)
      ->resize($attr['width'], $attr['height']);
  return $image->getUrl();
}

$appEmulation->startEnvironmentEmulation($storeId, \Magento\Framework\App\Area::AREA_FRONTEND, true);
$imageUrl = getImageURL($PRODUCT_ID_HERE);
$appEmulation->stopEnvironmentEmulation();

echo($imageUrl);

使用$appEmulation->startEnvironmentEmulation($storeId, \Magento\Framework\App\Area::AREA_FRONTEND, true);来防止获取http://<MAGENTO_ROOT>/pub/static/version1493842505/frontend/_view/en_US/Magento_Catalog/images/product/placeholder/.jpg