# ResizeImageOnUpload plugin and MODX3

**URL:** <https://community.modx.com/t/resizeimageonupload-plugin-and-modx3/6703>\
**Category:** Extras\
**Created:** [May 11, 2023, 9:05am UTC](https://community.modx.com/t/resizeimageonupload-plugin-and-modx3/6703 "2023-05-11T09:05:04Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![mr.tobe](https://community.modx.com/user_avatar/community.modx.com/mr.tobe/32/2724_2.png) [@mr.tobe](https://community.modx.com/u/mr.tobe)\
**Post date:** [May 11, 2023, 9:05am UTC](https://community.modx.com/t/resizeimageonupload-plugin-and-modx3/6703/1 "2023-05-11T09:05:04Z")

</div>

Hello everyone,  
Has anyone of you got the plugin “Resize Image On Upload” to work under Modx 3?

I changed the “require\_once” path from “/core/model/phpthumb/phpthumb.class.php” to “/core/vendor/james-heinrich/phpthumb/phpthumb.class.php”. This was displayed as an error in the error log. But after the change I have no more errors in the logs but it still doesn’t work properly.

Has anyone had any experience with this?

Alternative question: How do you do that for your customers/authors who are not technically versed that images are reduced in size when uploading?

Looking forward to your answers.

---

<div class="post-metadata">

**Author:** ![halftrainedharry](https://community.modx.com/user_avatar/community.modx.com/halftrainedharry/32/1063_2.png) [@halftrainedharry](https://community.modx.com/u/halftrainedharry)\
**Post date:** [May 11, 2023, 10:35am UTC](https://community.modx.com/t/resizeimageonupload-plugin-and-modx3/6703/2 "2023-05-11T10:35:40Z")

</div>

If the plugin property “log” is set to “Yes”, the plugin “ResizeImageOnUpload” should create a log file for each uploaded image with more information under `core/cache/logs/`. Maybe take a look at those files to make sure the file paths are correct.

* * *

When I test it in MODX 3, the plugin still seems to work.

The only problem I see, is when the image gets renamed on upload (system setting `upload_translit` = “Yes”). Because of a bug, the plugin code still gets the old file name and therefore can’t find the image file and resize it. To fix it, you may have to apply this pull request:

> <https://github.com/modxcms/revolution/pull/16196>
>
> Update uploadObjectsToContainer so the files array passed to the OnFileManagerUp…load event includes an up-to-date version of $objects. So if a file name has been renamed, $objects passed to the OnFileManagerUpload also reflects these changes.
> 
> \### What does it do?
> This ensures that $objects is kept up-to-date after looping through the array.
> 
> \### Why is it needed?
> Having an old file name triggered an unforced error in FileSluggy because the old file name was passed instead of the renamed filename.
> 
> \### How to test
> Install FileSluggy and try to upload a file with a name such as "Modx - Test.jpg". Now you'll see the unforced error:
> \`\`\`
> Error
> \- Modx - Test.jpg: The file is not a regular file and cannot be removed.
> \`\`\`
> Even though the file has been uploaded successfully and can also be removed.

---

<div class="post-metadata">

**Author:** ![mr.tobe](https://community.modx.com/user_avatar/community.modx.com/mr.tobe/32/2724_2.png) [@mr.tobe](https://community.modx.com/u/mr.tobe)\
**Post date:** [May 12, 2023, 7:38am UTC](https://community.modx.com/t/resizeimageonupload-plugin-and-modx3/6703/3 "2023-05-12T07:38:15Z")

</div>

Does the plugin really make the images smaller for you? I tested it with a 4.5MB image and after uploading it was over 5MB.

---

<div class="post-metadata">

**Author:** ![halftrainedharry](https://community.modx.com/user_avatar/community.modx.com/halftrainedharry/32/1063_2.png) [@halftrainedharry](https://community.modx.com/u/halftrainedharry)\
**Post date:** [May 12, 2023, 8:45am UTC](https://community.modx.com/t/resizeimageonupload-plugin-and-modx3/6703/4 "2023-05-12T08:45:57Z")

</div>

I tested it with the default settings and an image with the dimensions 3120x4208 pixels (7.04 MB). After the upload it has the dimensions 444x600 pixels and a size of 61.2 KB.

* * *

Maybe you could also try this extra:

[https://extras.modx.com/package/imageoptimonupload](https://extras.modx.com/package/imageoptimonupload)

I never used it. But it’s newer and seems to use an external API to optimize the images.

---

<div class="post-metadata">

**Author:** ![mr.tobe](https://community.modx.com/user_avatar/community.modx.com/mr.tobe/32/2724_2.png) [@mr.tobe](https://community.modx.com/u/mr.tobe)\
**Post date:** [May 15, 2023, 7:07am UTC](https://community.modx.com/t/resizeimageonupload-plugin-and-modx3/6703/5 "2023-05-15T07:07:57Z")

</div>

mhhhh…  
I just can’t get it to work properly. Do you have “phpThumbOn” or “pThumb” installed?

---

<div class="post-metadata">

**Author:** ![halftrainedharry](https://community.modx.com/user_avatar/community.modx.com/halftrainedharry/32/1063_2.png) [@halftrainedharry](https://community.modx.com/u/halftrainedharry)\
**Post date:** [May 15, 2023, 9:33am UTC](https://community.modx.com/t/resizeimageonupload-plugin-and-modx3/6703/6 "2023-05-15T09:33:52Z")

</div>

> [@mr.tobe](#):
>
> Do you have “phpThumbOn” or “pThumb” installed?

This is irrelevant. The plugin uses the _phpThumb_ PHP library directly.  
That’s why you had to change the path to “/core/vendor/james-heinrich/phpthumb/phpthumb.class.php”.

* * *

What PHP version are you using?  
With PHP 8, I get an error on the line

```auto
if (array_key_exists($cur_dir, $config)) {

```

because `$config` is `null`. This seems to be fixed in the Github code:

> <https://github.com/Setest/ResizeImageOnUpload/blob/30e01516275f681bf643ff549453caa2c9f599fb/core/components/resizeimageonupload/elements/plugins/plugin.resizeimageonupload.php#L322>

---

<div class="post-metadata">

**Author:** ![mr.tobe](https://community.modx.com/user_avatar/community.modx.com/mr.tobe/32/2724_2.png) [@mr.tobe](https://community.modx.com/u/mr.tobe)\
**Post date:** [May 15, 2023, 10:36am UTC](https://community.modx.com/t/resizeimageonupload-plugin-and-modx3/6703/7 "2023-05-15T10:36:52Z")

</div>

I tested this with php 7.4 - 8.1…  
The only error I have in the log is this:  
(ERROR @ /core/vendor/james-heinrich/phpthumb/phpthumb.class.php : 1814) PHP warning: getimagesize(/assets/bilder/test/Druckertest-A4.jpg): failed to open stream: No such file or directory

```auto
1813 ob_start();
1814 $getimagesize = getimagesize($this->sourceFilename);
1815 $GetImageSizeError = ob_get_contents();

```

mhhh strange…

If I simply make a call on the website, the images are calculated correctly.  
[[!phpthumbof? &input=`/assets/img/xxx.jpg` &options=`&w=640&h=480&zc=1&aoe=0&far=0`]]  
The images are then located as usual in “/core/cache/phpthumb/”

---

<div class="post-metadata">

**Author:** ![halftrainedharry](https://community.modx.com/user_avatar/community.modx.com/halftrainedharry/32/1063_2.png) [@halftrainedharry](https://community.modx.com/u/halftrainedharry)\
**Post date:** [May 15, 2023, 10:41am UTC](https://community.modx.com/t/resizeimageonupload-plugin-and-modx3/6703/8 "2023-05-15T10:41:12Z")

</div>

> [@mr.tobe](#):
>
> /assets/bilder/test/Druckertest-A4.jpg

So is this path correct? By default it should get converted to lowercase letters!  
Does it work if you use a file name with only lowercase letters? Did you apply the pull request I linked above?

---

<div class="post-metadata">

**Author:** ![mr.tobe](https://community.modx.com/user_avatar/community.modx.com/mr.tobe/32/2724_2.png) [@mr.tobe](https://community.modx.com/u/mr.tobe)\
**Post date:** [May 15, 2023, 10:50am UTC](https://community.modx.com/t/resizeimageonupload-plugin-and-modx3/6703/9 "2023-05-15T10:50:16Z")

</div>

Yes I made the change.  
Oh, good idea. I’ll try it with lower case letters.  
And yes, the path is correct…

---

<div class="post-metadata">

**Author:** ![mr.tobe](https://community.modx.com/user_avatar/community.modx.com/mr.tobe/32/2724_2.png) [@mr.tobe](https://community.modx.com/u/mr.tobe)\
**Post date:** [May 15, 2023, 10:54am UTC](https://community.modx.com/t/resizeimageonupload-plugin-and-modx3/6703/10 "2023-05-15T10:54:31Z")

</div>

Damn, it works with lower case letters now… The problem is that upper case letters are extremely common in our country. Now I just need to get something like “SanitizeUpload” working in Modx3.

---

<div class="post-metadata">

**Author:** ![halftrainedharry](https://community.modx.com/user_avatar/community.modx.com/halftrainedharry/32/1063_2.png) [@halftrainedharry](https://community.modx.com/u/halftrainedharry)\
**Post date:** [May 15, 2023, 11:10am UTC](https://community.modx.com/t/resizeimageonupload-plugin-and-modx3/6703/11 "2023-05-15T11:10:54Z")

</div>

> [@mr.tobe](#):
>
> Now I just need to get something like “SanitizeUpload” working in Modx3.

In MODX 3, the names of uploaded images are automatically transliterated, if the system setting `upload_translit` is set to `Yes`.

The problem is, that the changes to the file name are not transmitted correctly to the “OnFileManagerUpload” event. But this pull request fixed the issue when I tested it.

> <https://github.com/modxcms/revolution/pull/16196>
>
> Update uploadObjectsToContainer so the files array passed to the OnFileManagerUp…load event includes an up-to-date version of $objects. So if a file name has been renamed, $objects passed to the OnFileManagerUpload also reflects these changes.
> 
> \### What does it do?
> This ensures that $objects is kept up-to-date after looping through the array.
> 
> \### Why is it needed?
> Having an old file name triggered an unforced error in FileSluggy because the old file name was passed instead of the renamed filename.
> 
> \### How to test
> Install FileSluggy and try to upload a file with a name such as "Modx - Test.jpg". Now you'll see the unforced error:
> \`\`\`
> Error
> \- Modx - Test.jpg: The file is not a regular file and cannot be removed.
> \`\`\`
> Even though the file has been uploaded successfully and can also be removed.
