JS: fixing image saving issue