Replace assets / refresh properties



I am currently working on our old database and would like to update the pictures in the assets. There are currently > 200.000 pictures with a low resolution, which I would like to replace with the pictures with the original resolution. I can replace all images with the same name in the assets folder, but then the properties in the database remain (especially resolution information). How can I update and re-index this data?


You can write a command line job based on Pimcore PHP API for this. It would basically do following activities:

  1. Loop through all the image assets.
  2. Load each asset
  3. Update the new image into the asset
  4. Set additional properties if needed.
  5. Save the object back

Given the number of images, you should have some kind of logging and tracking in place to track the status progress and errors if any.

You can refer to documentation on how to work with Assets using PHP API here:


Yes, like @ramawadhprasad said, write a CLI script and use Symfony Console Progress to know the state. 200k images will take quite sometime. I would do it this way:

  • Create a Asset Listing with a paging of around 200
  • Loop thru that and increase paging until you don’t get any results anymore
  • For each asset, check if you have a new image
  • use $asset->setData(file_get_contents($pathToNewImage) to replace it

Thats about it

You could also look into the Pimcore source code and find where it gets and saves the resolution and do that for each asset in the loop.


Thanks for the reply :slight_smile:
Is the data from $pathToNewImage copied to the “old” location and is the old asset file on the server overwritten?


answer must be longer than 20 chars :smiley: