<p>Here's how i solved it:</p>

<pre><code>$criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Asset);
$criteria-&gt;id = $assetId;
$elements = $criteria-&gt;find();
$element[0]-&gt;getContent()-&gt;title = 'New Title';
craft()-&gt;elements-&gt;saveElement($element[0]);
</code></pre>

CC BY-SA 3.0
2016-01-12T19:12:36.437Z
Can you check this answer as best answer?
mohd4482
CC BY-SA 3.0
2015-04-03T19:25:20.427Z
2015-04-03T19:25:20.427Z
phaetons
<p>I save image files from within my plugin through <code>assets-&gt;insertFileByLocalPath()</code>. 
Unfortunately, i can't give the image title as paramter to the method.</p>

<p>What is the easiest way to change the image title after insert, espacially considering different languages?</p>

<p><strong>UPDATE</strong></p>

<p>Ok, i found a solution (moved to the answer), but how do i save values for different languages?</p>

CC BY-SA 3.0
2015-04-02T22:33:11.657Z
You should post that as an answer! To select a specific locale you would add `$criteria.locale = "en-us"`. Although you may want to save it without locale first so that it copies the titles to all locales by default; and then retrieve the specific locale using the above, overwrite the title, and save again.
Douglas McDonald
CC BY-SA 3.0
2015-04-03T19:22:06.453Z
you're right, i will post an answer. Thanks for the hint with the locale criteria!
phaetons
<plugin-development><assets>
Change image title programatically?
# Change image title programatically?

(Asked by: username_0 on 2015-04-02)

I save image files from within my plugin through `assets->insertFileByLocalPath()`.
Unfortunately, i can't give the image title as paramter to the method.

What is the easiest way to change the image title after insert, espacially considering different languages?

**UPDATE**

Ok, i found a solution (moved to the answer), but how do i save values for different languages?

**Tags:** plugin-development, assets
> **Comments:**
> **username_1**: You should post that as an answer! To select a specific locale you would add `$criteria.locale = "en-us"`. Although you may want to save it without locale first so that it copies the titles to all locales by default; and then retrieve the specific locale using the above, overwrite the title, and save again.  
> **username_0**: you're right, i will post an answer. Thanks for the hint with the locale criteria!  

---

## 1 answers

### Answer by username_0 on 2015-04-03. Score: 1

Here's how i solved it:
$criteria = craft()->elements->getCriteria(ElementType::Asset);
$criteria->id = $assetId;
$elements = $criteria->find();
$element[0]->getContent()->title = 'New Title';
craft()->elements->saveElement($element[0]);

> **Comments:**
> **username_2**: Can you check this answer as best answer?  

---

