php - Magento2 为产品图片添加动态背景

标签 php css image magento magento2

我正在 Magento2 平台上构建网站。 我需要为出售的艺术家的绘画添加图像。

需要的是除了上传图片外,我还想在画作中添加2-3张预定义的背景图片。 例如 - 餐厅、客厅。

我可以使用此代码在每页加载时(随机地)更改背景图像。

<head>
    <style type="text/css">
<!--
body{
background: url(images/<?php echo $selectedBg; ?>) no-repeat;
}
-->
</style>
</head>

<?php
  $bg = array('SET_A_01_Living.jpg', 'SET_A_02_Bed.jpg', 'SET_A_03_Study.jpg', 'SET_A_04_Dining.jpg' ); // array of filenames

  $i = rand(0, count($bg)-1); // generate random number size of the array
  $selectedBg = "$bg[$i]"; // set variable equal to which random filename was chosen
?>

但是我无法弄清楚我是如何将背景添加到图像和 Magento Gallery 中的。

对此的一些指导/提示将帮助我实现我正在尝试做的事情。

最佳答案

你必须像下面这样在 head 标签上方写 php :-

<?php
  $bg = array('SET_A_01_Living.jpg', 'SET_A_02_Bed.jpg', 'SET_A_03_Study.jpg', 'SET_A_04_Dining.jpg' ); // array of filenames

  $i = rand(0, count($bg)-1); // generate random number size of the array
  $selectedBg = $bg[$i]; // set variable equal to which random filename was chosen
?>

<head>
    <style type="text/css">
<!--
body{
background: url(images/<?php echo $selectedBg; ?>) no-repeat;
}
-->
</style>
</head>

关于php - Magento2 为产品图片添加动态背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48433492/

相关文章:

php - 修改 PHP 发布数据

通过代码下载php图像文件

jquery - Twitter Bootstrap 列类在表中不起作用

html - 如何制作一个 RESTful 搜索按钮?

html - 悬停时调整图像大小会使其他图像移动

java - 缩放和加载非常大的 TIFF 文件

PHP imagecreatefromstring() : gd-jpeg, libjpeg: 可恢复错误

php - 从youtube视频中获取带有用户个人资料图片的评论

PHP - 这是允许用户提供正则表达式的安全方法吗

html - 只对一张图片应用 css 样式