将照片分为X和Y片 [英] Divide photo to X and Y pieces

查看:391
本文介绍了将照片分为X和Y片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个96x96图像,我需要将它分成36个16x16并且我有一个下面给出的脚本在我的本地主机上正常工作但不能在我的虚拟主机上工作。

I have a 96x96 image and i need to divide it in 36 pieces of 16x16 and i have a script given below works fine on my localhost but not working on my webhost.

    function makeTiles($name, $imageFileName, $crop_width, $crop_height)
    {
    $dir = "/pic";
    $slicesDir = "/pic/16X16";

    // might be good to check if $slicesDir exists etc if not create it.
    $ImgExt = split(".",$imageFileName);
    $inputFile = $dir . $imageFileName;

    $img = new Imagick($inputFile);
    $imgHeight = $img->getImageHeight();
    $imgWidth = $img->getImageWidth();

    $cropWidthTimes = ceil($imgWidth/$crop_width);
    $cropHeightTimes = ceil($imgHeight/$crop_height);
    for($i = 0; $i < $cropWidthTimes; $i++)
    {
        for($j = 0; $j < $cropHeightTimes; $j++)
        {
            $img = new Imagick($inputFile);
            $x = ($i * $crop_width);
            $y = ($j * $crop_height);
            $img->cropImage($crop_width, $crop_height, $x, $y);
            $data = $img->getImageBlob();
            $newFileName = $slicesDir . $name . "_" . $x . "_" . $y . ".".$ImgExt[1];
            $result = file_put_contents ($newFileName, $data);
        }
    }
}

致命错误

Fatal error: Class 'Imagick' not found in myfile.php line number

我的主持人说:


不幸的是,Imagick和图像魔法都是一样的,我们没有
它们作为PHP模块我们有像ImageMagick二进制和
这样的二进制文件图像魔术路径是/ usr / local / bin。在您的
脚本中包含此功能,并检查您最终的网站功能。

Imagick and image magic both are same unfortunately, we do not have them as a PHP module we have binaries like ImageMagick binary and Image magic path is /usr/local/bin. Include this function in your script and check the website functionality from your end.

我不知道如何解决此错误。

I dont know how to fix this error.

推荐答案

如果我理解正确,你将不得不调用 imagick 使用 exec()的脚本中的二进制文件:

If I understand it correctly you will have to invoke the imagick binary from your script using exec():

 exec('/usr/local/bin/convert '.$inputFile.' -crop 96x96+ox+oy '.$newFilename);

ox oy 应替换为正确的偏移值。

The ox and oy should be replaced with the correct offset values.

以下是一些可能有用的链接:

Here is are a couple of links that might help:


  1. 我如何使用来自php的Imagick二进制文件

  2. Imagick - 转换命令行工具

  1. How do I use Imagick binaries from php
  2. Imagick - Convert Command-line tool

这篇关于将照片分为X和Y片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆