Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-05T03:21:29.260Z
Answers.LastActivityDate: 2020-06-05T03:21:29.260Z
Answers.UserDisplayName: Leevi Graham
Body: <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>
  
Tags: <assets>
Title: Convert a PHP image resource to a new Asset
ThreadText: # 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>
  
  
  ---
  
  