too long

我是新手imagemagic又名想象力在php上我试图跟随此主题使用php代码。 我试图将这个徽标应用到T恤上,但不能通过跟随线索这样做,因为我无法找到php中的大多数方法,比如使用置换贴图开始。 我试过的是以下代码:</ p>

  $ image = new Imagick($ _ SERVER ['DOCUMENT_ROOT']。'/ images / VHLZsoD.jpg');

$ logo = new Imagick($ _ SERVER ['DOCUMENT_ROOT']。'/ images / logo.png');
nnlogo -> resizeImage(200,200,imagick :: FILTER_LANCZOS,1,TRUE);

header(“Content-Type:image / jpg”);

$ image-&gt; compositeimage($ logo,Imagick :: COMPOSITE_DEFAULT,400,260);

$ image-&gt; flattenImages();

echo $ image;
</ code> </ pre>

我想使用线程中显示的步骤创建一个掩码 等等,以便使用PHP代码(而不是通过命令)将徽标应用到T恤上。 我甚至使用“COMPOSITE_OVERLAY”使徽标看起来像是T恤的一部分,但由于透明度,徽标的原始颜色似乎有所减少,点击此处查看我的最终T恤http://i62.tinypic.com/2ahuw6h.png 。</ p>


  1. 请告诉我如何使用php中的imagick存档更好的结果(不会减少徽标的颜色)</ li>
  2. 我可以在T恤上标记一个区域,这样当我拖动徽标时 ,它不会显示在T恤边框外?</ li>
    </ ol>

    来源t恤http://i58.tinypic.com/154j52b.jpg
    来源徽标http://i59.tinypic.com/e02051.png </ p>
    </ div>

展开原文

原文

I'm new to imagemagic aka imagick on php and im trying to follow this thread using php code. I have tried to apply this logo onto a tshirt but couldn't do so by following the threas becuase i cannot find most of the methods in php like using displacement map to start with. What i have tried is the following code:

$image = new Imagick($_SERVER['DOCUMENT_ROOT'] . '/images/VYLZsoD.jpg');    
$logo = new Imagick($_SERVER['DOCUMENT_ROOT'] . '/images/logo.png');
$logo->resizeImage(200, 200, imagick::FILTER_LANCZOS, 1, TRUE);    
header("Content-Type: image/jpg");

$image->compositeimage($logo, Imagick::COMPOSITE_DEFAULT, 400, 260); 
$image->flattenImages();

echo $image;

I would want to use the steps shown in the thread to create a mask and so on in order to apply the logo onto the tshirt using php code (not via command). I have even used "COMPOSITE_OVERLAY" to make the logo look like its part of the tshirt but it seems like the original color of the logo reduces because of the transparency, check here for my final tshirt http://i62.tinypic.com/2ahuw6h.png.

  1. Please tell me how i can archive a better result using imagick in php (without the color of the logo is being reduced)
  2. Can i mark a territory on the tshirt so that when i drag the logo around, it wouldn't show outside the tshirt border?

Source tshirt http://i58.tinypic.com/154j52b.jpg Source logo http://i59.tinypic.com/e02051.png

dsgo31121
dsgo31121 谢谢。我刚才上传了它们。检查原始帖子
6 年多之前 回复
dongshi2588
dongshi2588 你可以发布源图像吗?
6 年多之前 回复

4个回答



我希望, this 效果会对你有所帮助。 </ p>

(此页面有很多效果,因此您可以使用F3(tshirt)进行搜索)</ em> </ p>
</ div>

展开原文

原文

I hope, this effects will help you.

(this page has much effects, so you can search with F3 (tshirt) )

duanhuayong6687
duanhuayong6687 一点也不.. :)
接近 6 年之前 回复
doutale7115
doutale7115 非常感谢你 :)
接近 6 年之前 回复



您发布的输出图像与我在运行代码时看到的输出图像不同。 显然稍微调整位置,我看到的输出图像没有减少颜色。 </ p>

</ p>

< p>如果您没有看到相同的内容,则可能是您的ImageMagick版本中的错误。 您可以尝试使用复合方法COMPOSITE_ATOP,它应该通过不同的混合方法产生相同的结果。</ p>

对于第二个问题,如何将徽标覆盖限制在T恤的边缘 ,你可以通过在T恤上创建一个面具,用COMPOSITE_SRCIN将徽标绘制到该面具上,然后将其结果绘制到T恤上来实现:</ p>

  $ tshirt =  new \ Imagick(realpath(“../ images / tshirt / tshirt.jpg”)); 
$ logo = new \ Imagick(realpath(“../ images / tshirt / Logo.png”));
$ logo-&gt; resizeImage(100,100,\ Imagick :: FILTER_LANCZOS,1,TRUE);

$ tshirt-&gt; setImageFormat('png');

$ max = $ image-&gt; getQuantumRange ();
$ max = $ max [“quantumRangeLong”];

//通过克隆衬衫创建一个蒙版,
$ mask = clone $ tshirt;
//否定图像,
$ mask-&gt; negateimage(true);
//使它在任何地方都是透明的,现在它是白色的。
$ mask-&gt; transparentPaintImage(
'black',
0,
0.1 * $ max,
false
);

//将徽标绘制到蒙版上,SRCIN只使用徽标的颜色
$ mask-&gt; compositeimage($ logo,\ Imagick :: COMPOSITE_SRCIN,210 ,75);
//将徽标+蒙版的结果绘制到T恤上。
$ tshirt-&gt; compositeimage($ mask,\ Imagick :: COMPOSITE_DEFAULT,0,0);
//合并图像 具有非弃用功能。
$ tshirt-&gt; mergeimagelayers(\ Imagick :: LAYERMETHOD_COALESCE);

标题(“Content-Type:image / png”);
echo $ tshirt-&gt; getImageBlob( );
}
</ code> </ pre>

它产生类似于:</ p>

</ p>

这是否是个好主意是另一回事。</ p>
</ div>

展开原文

原文

The output image you posted doesn't look like the output image I see when running your code. Obviously adjusting the position a little, the output image I see doesn't have the color reduced.

enter image description here

If you don't see see the same thing, it may be a bug in your version of ImageMagick. You could try using the composite method COMPOSITE_ATOP, which should produce the same result, via a different blend method.

For your second question, how to limit the logo overlay to the edge of the Tshirt, you can do it by creating a mask out of the tshirt, painting the logo onto that mask with COMPOSITE_SRCIN and then painting the result of that onto the tshirt:

    $tshirt = new \Imagick(realpath("../images/tshirt/tshirt.jpg"));
    $logo = new \Imagick(realpath("../images/tshirt/Logo.png"));
    $logo->resizeImage(100, 100, \Imagick::FILTER_LANCZOS, 1, TRUE);

    $tshirt->setImageFormat('png');

    $max = $image->getQuantumRange();
    $max = $max["quantumRangeLong"];

    //Create a mask by cloning the shirt,
    $mask = clone $tshirt;
    //Negating the image,
    $mask->negateimage(true);
    //Make it transparent everywhere that it is now white.
    $mask->transparentPaintImage(
        'black', 
        0, 
        0.1 * $max, 
        false
    );

    //Paint the logo onto the mask, SRCIN just uses the logo's color
    $mask->compositeimage($logo, \Imagick::COMPOSITE_SRCIN, 210, 75);
    //Paint the result of the logo + mask onto the tshirt.
    $tshirt->compositeimage($mask, \Imagick::COMPOSITE_DEFAULT, 0, 0);
    //Merge the image with a non-deprecated function.
    $tshirt->mergeimagelayers(\Imagick::LAYERMETHOD_COALESCE);

    header("Content-Type: image/png");
    echo $tshirt->getImageBlob();
}

Which produces something like:

enter image description here

Whether that's a good idea or not is another matter.

dragon012100
dragon012100 你能为它提供一个示例代码吗? 说实话,我不是imagemagick专业人士。
6 年多之前 回复
doucandiao9180
doucandiao9180 您需要做的是将图像卷积以产生“折痕”蒙版然后将其应用于徽标 - 但是看起来可能在ImageMagick中被破坏 - stackoverflow.com/questions/24184801 / ...
6 年多之前 回复
douce1368
douce1368 too long
6 年多之前 回复

The second part of your question, how to get the creases to show through 'nicely' is possibly a bad idea. There are two problems with attempting it:

i) The distortions in the tshirt are physical displacements. Although you can get the crease lighting to show through, it's really hard to get the logo to look realistic without also having the same physical displacement.

ii) Colors really don't behave consistently. Just having the logo be lighter/darker by the same amount as the tshirt crease may produce unrealistic effects. e.g. dark tshirt + crease = 50% brighter background. Bright blue logo + 50% brighter crease effect = unrealistic looking blue highlight.

I would recommend having a flat tshirt as the background as unrealistic effects tend to distract people. But you could do it like this:

function getAverageColorString(\Imagick $imagick) {

    $tshirtCrop = clone $imagick;
    $tshirtCrop->cropimage(100, 100, 90, 50);
    $stats = $tshirtCrop->getImageChannelStatistics();
    $averageRed = $stats[\Imagick::CHANNEL_RED]['mean'];
    $averageRed = intval(255 * $averageRed / \Imagick::getQuantum());
    $averageGreen = $stats[\Imagick::CHANNEL_GREEN]['mean'];
    $averageGreen = intval(255 * $averageGreen / \Imagick::getQuantum());
    $averageBlue = $stats[\Imagick::CHANNEL_BLUE]['mean'];
    $averageBlue = intval(255 * $averageBlue / \Imagick::getQuantum());
    $colorString = "rgb($averageRed, $averageGreen, $averageBlue)";

    return $colorString;
}


$tshirt = new \Imagick(realpath("../images/tshirt/tshirt.jpg"));
$logo = new \Imagick(realpath("../images/tshirt/Logo.png"));
$logo->resizeImage(100, 100, \Imagick::FILTER_LANCZOS, 1, TRUE);

$tshirt->setImageFormat('png');

//First lets find the creases
//Get the average color of the tshirt and make a new image from it.
$colorString = getAverageColorString($tshirt);
$creases = new \Imagick();
$creases->newpseudoimage(
   $tshirt->getImageWidth(),
   $tshirt->getImageHeight(), 
   "XC:".$colorString
);

//Composite difference finds the creases
$creases->compositeimage($tshirt, \Imagick::COMPOSITE_DIFFERENCE, 0, 0);
$creases->setImageFormat('png');
//We need the image negated for the maths to work later. 
$creases->negateimage(true);
//We also want "no crease" to equal 50% gray later
//$creases->brightnessContrastImage(-50, 0); //This isn't in Imagick head yet, but is more sensible than the modulate function.
$creases->modulateImage(50, 100, 100);

//Copy the logo into an image the same size as the shirt image
//to make life easier
$logoCentre = new \Imagick();
$logoCentre->newpseudoimage(
   $tshirt->getImageWidth(),
   $tshirt->getImageHeight(),
   "XC:none"
);
$logoCentre->setImageFormat('png');
$logoCentre->compositeimage($logo, \Imagick::COMPOSITE_SRCOVER, 110, 75);

//Save a copy of the tshirt sized logo
$logoCentreMask = clone $logoCentre;

//Blend the creases with the logo
$logoCentre->compositeimage($creases, \Imagick::COMPOSITE_MODULATE, 0, 0);

//Mask the logo so that only the pixels under the logo come through
$logoCentreMask->compositeimage($logoCentre, \Imagick::COMPOSITE_SRCIN, 0, 0);

//Composite the creased logo onto the shirt
$tshirt->compositeimage($logoCentreMask, \Imagick::COMPOSITE_DEFAULT, 0, 0);

//And Robert is your father's brother
header("Content-Type: image/png");
echo $tshirt->getImageBlob();

Produces an image like:

enter image description here

doubianyu7844
doubianyu7844 并不是的。 您发布的代码适合我。 我只能假设您正在使用带有错误的ImageMagick版本。 例如 这是图像i.stack.imgur.com/0Uypu.png,其中包含徽标位置/尺寸。 您可能应该测试每个步骤,以查看徽标转向黑色的位置。
6 年多之前 回复
duanliexi1052
duanliexi1052 任何想法,为什么我得到黑色标志?
6 年多之前 回复
douyan4958
douyan4958 $ max = $ image-> getQuantumRange(); $ max = $ max [“quantumRangeLong”]; - 该函数将出现在Imagick的下一个版本中。
6 年多之前 回复
donglunzai4288
donglunzai4288 我一定会试试这个。 有没有另一种方法来获得这个“\ Imagick :: getQuantum()”它说它是一个未完成的方法。
6 年多之前 回复

Here;s the final code for my 2nd question:

<?php

// Let's check whether we can perform the magick.
if (TRUE !== extension_loaded('imagick')) {
    throw new Exception('Imagick extension is not loaded.');
}

// This check is an alternative to the previous one.
// Use the one that suits you better.
if (TRUE !== class_exists('Imagick')) {
    throw new Exception('Imagick class does not exist.');
}

function getAverageColorString(\Imagick $imagick) {

    $max = $imagick->getquantumrange(); 
    $max = $max["quantumRangeLong"];

    $tshirtCrop = clone $imagick;
    $tshirtCrop->cropimage(100, 100, 90, 50);
    $stats = $tshirtCrop->getImageChannelStatistics();
    $averageRed = $stats[\Imagick::CHANNEL_RED]['mean'];
    $averageRed = intval(255 * $averageRed / $max);
    $averageGreen = $stats[\Imagick::CHANNEL_GREEN]['mean'];
    $averageGreen = intval(255 * $averageGreen / $max);
    $averageBlue = $stats[\Imagick::CHANNEL_BLUE]['mean'];
    $averageBlue = intval(255 * $averageBlue / $max);
    $colorString = "rgb($averageRed, $averageGreen, $averageBlue)";

    return $colorString;
}

//final product
$tshirt = new \Imagick($_SERVER['DOCUMENT_ROOT'] . '/images/VYLZsoD.jpg');
$logo = new \   Imagick($_SERVER['DOCUMENT_ROOT'] . '/logo.png');
$logo->resizeImage(100, 100, imagick::FILTER_LANCZOS, 1, TRUE);

$tshirt->setImageFormat('png');

//First lets find the creases
//Get the average color of the tshirt and make a new image from it.
$colorString = getAverageColorString($tshirt);
$creases = new \Imagick();
$creases->newpseudoimage(
   $tshirt->getImageWidth(),
   $tshirt->getImageHeight(), 
   "XC:".$colorString
);

//Composite difference finds the creases
$creases->compositeimage($tshirt, \Imagick::COMPOSITE_DIFFERENCE, 0, 0);
$creases->setImageFormat('png');
//We need the image negated for the maths to work later. 
$creases->negateimage(true);
//We also want "no crease" to equal 50% gray later
//$creases->brightnessContrastImage(-50, 0); //This isn't in Imagick head yet, but is more sensible than the modulate function.
$creases->modulateImage(50, 100, 100);

//Copy the logo into an image the same size as the shirt image
//to make life easier
$logoCentre = new \Imagick();
$logoCentre->newpseudoimage(
   $tshirt->getImageWidth(),
   $tshirt->getImageHeight(),
   "XC:none"
);
$logoCentre->setImageFormat('png');
$logoCentre->compositeimage($logo, \Imagick::COMPOSITE_SRCOVER, 110, 75);

//Save a copy of the tshirt sized logo
$logoCentreMask = clone $logoCentre;

//Blend the creases with the logo
$logoCentre->compositeimage($creases, \Imagick::COMPOSITE_MODULATE, 0, 0);

//Mask the logo so that only the pixels under the logo come through
$logoCentreMask->compositeimage($logoCentre, \Imagick::COMPOSITE_SRCIN, 0, 0);

//Composite the creased logo onto the shirt
$tshirt->compositeimage($logoCentreMask, \Imagick::COMPOSITE_DEFAULT, 0, 0);

//And Robert is your father's brother
header("Content-Type: image/png");
echo $tshirt->getImageBlob();
?>

Output Output http://i59.tinypic.com/23h7nzs.png

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐