将HALD CLUT与ImageMagick一起使用时出错输出图像上的黑线

如何解决将HALD CLUT与ImageMagick一起使用时出错输出图像上的黑线

我是一个预制站点上的新开发人员,试图弄清楚如何使用设置的ImageMagick工具。我们使用它的方式是使用HALD CLUT滤镜自动更改产品的颜色。

我昨天让它运行了,但是输出图像上全是黑线。我测试了产品图像和HALD CLUT过滤器上更改的文件类型/格式,但是没有运气,所以我假设它与ImageMagick有关。

Screen capture of outputted image

有人知道会导致什么原因吗?

这是ImageMagick颜色生成器的代码:

class SwatchGenerator {
    public $mask;
    public $swatches;
    public $types;
    public $th;
    public $base_url;
    public $results;
    public $type;
    public $color;
    public $output;

    function __construct ($overwrite = false) {
        $this->th = \Loader::helper('text');
        $this->base_url = \View::url('/');
        $this->overwrite = $overwrite;
        $this->delimiter = '~';
        $this->results = [];

        $this->loadSwatches();
        $this->loadTypes();
    }

    function loadSwatches () {
        $swatches = \Express::getObjectByHandle('swatch')->getEntries();

        foreach ($swatches as $swatch) {
            $handle = $this->th->urlify($swatch->getSwatchName());
            $filter = $swatch->getSwatchFilter();
            $this->swatches[$handle] = (is_object($filter)) ? $this->getImagickInstance($filter) : false;
        }
    }

    function loadTypes () {
        $types = \Concrete\Core\File\Image\Thumbnail\Type\Type::getVersionList();

        foreach ($types as $type) {
            $type_handle = $type->getHandle();

            if (strpos($type_handle,'_2x') === false && strpos($type_handle,'product_') !== false) {
                $this->types[$type_handle] = $type;
            }
        }
    }

    function setType ($type) {
        $this->type = $type;
    }

    function setColor ($color) {
        $this->color = $color;
    }

    function setOutput ($output) {
        $this->output = $output;
    }

    function log ($message) {
        $this->addResult($message);

        // \Log::addEntry($message);
    }

    function addResult ($message) {
        $this->results[] = $message;
    }

    function getResults () {
        return $this->results;
    }

    function getResultLog ($delimiter = "\n\r") {
        return implode("\n\r",$this->getResults());
    }

    function generate ($base_file,$allowed_type = false) {
        $mask_file = $base_file->getAttribute('color_mask');

        if (!is_object($mask_file)) {
            $this->log('Mask not found.');
            return;
        }

        if ($base_file->getAttribute('width') != 2560) {
            $this->log('Invalid image size found. Must be 2560px wide.');
            return;
        }

        // these are our core images that should not change for any swatch
        $base = $this->getImagickInstance($base_file);

        // we do this to remove any trace of transparency and flatten the file
        // resolves issues with odd masking we were seeing
        $base->setImageBackgroundColor('white');
        // $base->setImageAlphaChannel(Imagick::ALPHACHANNEL_REMOVE);
        $base->setImageAlphaChannel(11);
        $base->mergeImageLayers(Imagick::LAYERMETHOD_FLATTEN);

        // jpg output
        $base->setImageFormat('jpg');
        $base->setImageCompressionQuality(85);

        $mask = $this->getImagickInstance($mask_file);
        $overlay = clone ($base);
        $overlay->compositeImage($mask,Imagick::COMPOSITE_COPYOPACITY,0);

        // base path to write the swatches to
        $base_file = $this->parsePath($base_file->getRelativePath());
        $pathinfo = pathinfo($base_file);

        // stores our composited swatch images
        $swatches = [];

        // now create an image for each swatch we have
        foreach ($this->swatches as $swatch_handle => $filter) {
            // if we are limited to a color,then abort if we are not on it
            if ($this->color && $this->color != $swatch_handle) {
                continue;
            }

            $swatch = clone ($base);

            if ($filter) {
                $swatch->haldClutImage($filter);
            }

            $swatch->compositeImage($overlay,imagick::COMPOSITE_DEFAULT,0);

            $swatches[$swatch_handle] = $swatch;

            foreach ($this->types as $type_handle => $type) {
                // filter non-product types
                if ($allowed_type && $allowed_type !== $type_handle) {
                    continue;
                }

                // if we are limited to a type,then abort if we are not on it
                if ($this->type && $this->type != $type_handle) {
                    continue;
                }

                $output_path = $pathinfo['dirname'] . '/' . $pathinfo['filename'] . $this->delimiter . $type_handle . $this->delimiter . $swatch_handle . '.jpg';

                if (file_exists($output_path) && !$this->overwrite) {
                    $this->log('Skipping existing file at ' . $output_path);
                } else {
                    $this->log('Rendering ' . $this->th->unhandle($swatch_handle) . ' at ' . $type->getWidth() . 'px (' . $type_handle . ')');

                    $output = clone ($swatch);
                    $output->resizeImage($type->getWidth(),Imagick::FILTER_LANCZOS,0);
                    $output->writeImage('../' . $output_path);

                    if ($this->output) {
                        $this->addResult("<img src='/{$output_path}' />");
                    }
                }

            }
        }
    }

    function getImagickInstance ($file,$type = false) {
        if (is_object($file)) {
            $path = ($type) ? $file->getThumbnailURL($type) : $file->getRelativePath();

            $image = new Imagick($this->parsePath('../' . $path));
            $image->setImageFormat('png');
            $image->setFormat('png');

            return $image;
        }
    }

    function parsePath ($path) {
        // strip leading slash
        $path = preg_replace('/^\//','',$path);

        return str_replace($base_url,$path);
    }
}

我使用的是PHP版本7.0.3.3,Imagick版本3.4.3和ImageMagick 6.9.6-2。

解决方法

我无法访问您的原始图片。但是我确实下载了您的Hald图片。所以我在命令行中将其应用于ImageMagick 6.9.11.28 Q16 Mac OSX中的以下图像,它可以正常工作-至少没有行。因此,我怀疑您的ImageMagick版本或Imagick版本或您的代码有问题。您可以尝试在PHP exec()中运行我的命令,看看是否可行。它会告诉您ImageMagick是否正常工作。您的输入图像或libpng委托版本也可能有问题。

输入:

enter image description here

Hald图片:

enter image description here

convert lena.jpg hald.png -hald-clut result.png

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-