# Upsized Image on getting with request

**URL:** <https://discourse.getcockpit.com/t/upsized-image-on-getting-with-request/1285>\
**Category:** Support\
**Created:** [March 23, 2020, 1:34am UTC](https://discourse.getcockpit.com/t/upsized-image-on-getting-with-request/1285 "2020-03-23T01:34:42Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![joko\_pain](https://avatars.discourse-cdn.com/v4/letter/j/ecccb3/32.png) [@joko\_pain](https://discourse.getcockpit.com/u/joko_pain)\
**Post date:** [March 23, 2020, 1:34am UTC](https://discourse.getcockpit.com/t/upsized-image-on-getting-with-request/1285/1 "2020-03-23T01:34:42Z")

</div>

Hi everyone, I have a issue with getting image url. When I getting it with url like this “/api/cockpit/image?token=xxtokenxx&src=path&w=1920&h=1200&o=true”  
it returns image with normal size, but when i do it with axios request like this:

```
 export const assetsAPI = async (path) => {
  let response = await instance.post(`/api/cockpit/image`, {
    src: path,
    m: "thumbnail",
    w: 1920,           
    h: 1200           
})
return response.data; 
}

```

It returns 3+mb image, but original image wich i uploaded is about 800kb, and i checked it on server and my original image still 800kb but new one in “thumbnail” folder is 3+mb

What`s the problem is?

---

<div class="post-metadata">

**Author:** ![raffaelj](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/raffaelj/32/331_2.png) [@raffaelj](https://discourse.getcockpit.com/u/raffaelj)\
**Post date:** [March 23, 2020, 6:29pm UTC](https://discourse.getcockpit.com/t/upsized-image-on-getting-with-request/1285/2 "2020-03-23T18:29:38Z")

</div>

Is it a png file? The inbuilt image library (SimpleImage, based on PHP GD lib) is horrible with resizing (already optimized) png files.

---

<div class="post-metadata">

**Author:** ![joko\_pain](https://avatars.discourse-cdn.com/v4/letter/j/ecccb3/32.png) [@joko\_pain](https://discourse.getcockpit.com/u/joko_pain)\
**Post date:** [March 23, 2020, 7:35pm UTC](https://discourse.getcockpit.com/t/upsized-image-on-getting-with-request/1285/3 "2020-03-23T19:35:28Z")

</div>

Yes it was already optimized png then i chenged it to optimized jpg file, jpg is better but still make it bigger, what i can do?

---

<div class="post-metadata">

**Author:** ![raffaelj](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/raffaelj/32/331_2.png) [@raffaelj](https://discourse.getcockpit.com/u/raffaelj)\
**Post date:** [March 24, 2020, 2:11pm UTC](https://discourse.getcockpit.com/t/upsized-image-on-getting-with-request/1285/4 "2020-03-24T14:11:02Z")

</div>

> [@joko\_pain](#):
>
> what i can do?

Set the quality to 70% instead of 100%: `q: 70`.

I didn’t test the ImageOptimizer addon, yet. Maybe that helps.

> [@New addon - ImageOptimizer](https://discourse.getcockpit.com/t/new-addon-imageoptimizer/1050):
>
> Very simple addon that integrates with Spatie Image Optimizer and provides out of the box image optimization when saving an asset - [https://github.com/pauloamgomes/CockpitCMS-ImageOptimizer](https://github.com/pauloamgomes/CockpitCMS-ImageOptimizer) Interesting that checking some cloud services (e.g. tinypng, resmush, kraken, etc…) and differences in file size are minimal when compared with the available php binaries that are used by Spatie library.

Besides that, I’m aware of that bug since a few months and I didn’t find a real solution, yet. Setting the qualitiy helps for jpg files, but not really for png files. So, when I have full control, I replace some png icons with svg icons and I upload png images in the needed output format. When I don’t resize them, the original file is delivered. It’s a bad workaround, but the best one, I found for png files so far.

---

<div class="post-metadata">

**Author:** ![joko\_pain](https://avatars.discourse-cdn.com/v4/letter/j/ecccb3/32.png) [@joko\_pain](https://discourse.getcockpit.com/u/joko_pain)\
**Post date:** [March 24, 2020, 4:42pm UTC](https://discourse.getcockpit.com/t/upsized-image-on-getting-with-request/1285/5 "2020-03-24T16:42:41Z")

</div>

Thanks for help, i tested “ImageOptimizer” it still horrible with png but such better with jpg. I realy love “Cockpit” but this problem spoils everything. I will be waiting for solution, but for now can I denide upload png file? So that the end user could not make a mistake.

---

<div class="post-metadata">

**Author:** ![raffaelj](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/raffaelj/32/331_2.png) [@raffaelj](https://discourse.getcockpit.com/u/raffaelj)\
**Post date:** [March 24, 2020, 5:01pm UTC](https://discourse.getcockpit.com/t/upsized-image-on-getting-with-request/1285/6 "2020-03-24T17:01:32Z")

</div>

You can restrict allowed file extensions for uploads in `/config/config.yaml`.

```auto
# define allowed file types for uploads (global)
assets.allowed_uploads: png, jpg, jpeg

# define allowed file types for uploads (for user groups)
groups:
    author:
        $admin: false
        $vars:
            assets.allowed_uploads: png, jpg, jpeg

```

It doesn’t throw an useful notification to the user, why it isn’t allowed to upload a png, but only something like “Something went wrong”. The whole assets management needs some refactoring…

---

<div class="post-metadata">

**Author:** ![pauloamgomes](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/pauloamgomes/32/48_2.png) [@pauloamgomes](https://discourse.getcockpit.com/u/pauloamgomes)\
**Post date:** [March 24, 2020, 7:15pm UTC](https://discourse.getcockpit.com/t/upsized-image-on-getting-with-request/1285/7 "2020-03-24T19:15:34Z")

</div>

Keep in mind that the ImageOptimizer will work only on the uploaded assets. When you are using the image API the image will be generated again using a different library, and as @raffaelj mentioned, it doesn’t handle properly PNGs.  
One possible solution is to do a feature request to permit hooking into the image API request and therefore do the thumbnail with a custom addon.

---

<div class="post-metadata">

**Author:** ![joko\_pain](https://avatars.discourse-cdn.com/v4/letter/j/ecccb3/32.png) [@joko\_pain](https://discourse.getcockpit.com/u/joko_pain)\
**Post date:** [March 24, 2020, 8:04pm UTC](https://discourse.getcockpit.com/t/upsized-image-on-getting-with-request/1285/8 "2020-03-24T20:04:13Z")

</div>

Yes, I already realized that ImageOptimizer will not help when working with image APIs, but anyway thanks for the addon, it works great.  
And how difficult and how much possible is to make the generation of thumbnail when requesting through the API go through your or some other library with normal support for PNG?  
As it seems to me this is a rather serious mistake and it is surprising that it has not yet been fixed
