<p>You'll need to save the image to the filesystem and use that path as $tempPath.</p>

<p><a href="https://www.php.net/manual/en/image.examples.merged-watermark.php" rel="nofollow noreferrer">https://www.php.net/manual/en/image.examples.merged-watermark.php</a></p>

CC BY-SA 4.0
2020-06-05T03:21:29.260Z
2020-06-05T03:21:29.260Z
Leevi Graham
<p>I am trying to merge two images and save it as a new asset and I am using the PHP function called "imagecopymerge" (<a href="https://www.php.net/manual/en/function.imagecopymerge.php" rel="nofollow noreferrer">https://www.php.net/manual/en/function.imagecopymerge.php</a>) however thats returning a "resource" and I have tried figuring out how I can turn that "resource" into something I can use to save using perhaps $tempath?</p>

<pre><code>$newAsset = new Asset();
$newAsset-&gt;avoidFilenameConflicts = true;
$newAsset-&gt;setScenario(Asset::SCENARIO_CREATE);
$newAsset-&gt;tempFilePath = $tempPath;
Craft::$app-&gt;getElements()-&gt;saveElement($newAsset);
</code></pre>

<assets>
Convert a PHP image resource to a new Asset
# Convert a PHP image resource to a new Asset

(Asked by: username_0 on 2020-06-04)

I am trying to merge two images and save it as a new asset and I am using the PHP function called "imagecopymerge" (https://www.php.net/manual/en/function.imagecopymerge.php) however thats returning a "resource" and I have tried figuring out how I can turn that "resource" into something I can use to save using perhaps $tempath?
$newAsset = new Asset();
$newAsset->avoidFilenameConflicts = true;
$newAsset->setScenario(Asset::SCENARIO_CREATE);
$newAsset->tempFilePath = $tempPath;
Craft::$app->getElements()->saveElement($newAsset);

**Tags:** assets

---

## 1 answers

### Answer by username_1 on 2020-06-05. Score: 2

You'll need to save the image to the filesystem and use that path as $tempPath.

<https://www.php.net/manual/en/image.examples.merged-watermark.php>


---

