Convert image

Convert image [Paid] 4.7

No permission to buy ($35.00)
Hello Andy. I updated our backend to PHP 7.2.8. Imagick is still installed. However, This addon no longer works.

1533334941617.webp
1533334917609.webp


I get this error:

Server error log

Error: Class 'Imagick' not found
src/addons/Andy/ConvertImage/Listener.php:297


Stack trace

#0 [internal function]: Andy\ConvertImage\Listener::threadEntityPostSave(Object(SV\ThreadReplyBanTeeth\XF\Entity\Post))
#1 src/XF/Extension.php(50): call_user_func_array(Array, Array)
#2 src/XF.php(1121): XF\Extension->fire('entity_post_sav...', Array, 'XF\\Entity\\Post')
#3 src/XF/Mvc/Entity/Entity.php(1151): XF::fire('entity_post_sav...', Array, 'XF\\Entity\\Post')
#4 src/XF/Service/Thread/Replier.php(161): XF\Mvc\Entity\Entity->save(true, false)
#5 src/XF/Service/ValidateAndSavableTrait.php(40): XF\Service\Thread\Replier->_save()
#6 src/XF/Pub/Controller/Thread.php(431): XF\Service\Thread\Replier->save()
#7 src/XF/Mvc/Dispatcher.php(249): XF\Pub\Controller\Thread->actionAddReply(Object(XF\Mvc\ParameterBag))
#8 src/XF/Mvc/Dispatcher.php(88): XF\Mvc\Dispatcher->dispatchClass('XF:Thread', 'AddReply', 'json', Object(XF\Mvc\ParameterBag), 'forums', Object(Andy\InsertAttachment\XF\Pub\Controller\Thread), NULL)
#9 src/XF/Mvc/Dispatcher.php(41): XF\Mvc\Dispatcher->dispatchLoop(Object(XF\Mvc\RouteMatch))
#10 src/XF/App.php(1931): XF\Mvc\Dispatcher->run()
#11 src/XF.php(655): XF\App->run()
#12 index.php(13): XF::runApp('XF\\Pub\\App')
#13 {main}



Request state



array(4) {
["url"] => string(63) "/threads/weekly-wrist-shots-30th-july-5th-august.1489/add-reply"
["referrer"] => string(89) "https://www.domain.com/threads/weekly-wrist-shots-30th-july-5th-august.1489/page-4"
["_GET"] => array(0) {
}
["_POST"] => array(10) {
["message_html"] => string(170) "<p>Image test</p><p><br></p><p><img src="https://domain2.com/i/2018/08/03/fiPb.jpg" class="bbImage fr-fic fr-dii" alt="" data-url="https://domain2.com/i/2018/08/03/fiPb.jpg"></p>"
["attachment_hash"] => string(32) "a445c8e45c8eb332cca4a629374cf77a"
["attachment_hash_combined"] => string(86) "{"type":"post","context":{"thread_id":1489},"hash":"a445c8e45c8eb332cca4a629374cf77a"}"
["last_date"] => string(10) "1533322406"
["last_known_date"] => string(10) "1533322406"
["_xfToken"] => string(8) "********"
["ct_checkjs"] => string(4) "2018"
["_xfRequestUri"] => string(60) "/threads/weekly-wrist-shots-30th-july-5th-august.1489/page-4"
["_xfWithData"] => string(1) "1"
["_xfResponseType"] => string(4) "json"
}
}
 
So XF has a Maximum image attachment dimensions, where it will automatically resize any image down to these values, say 1600x1600. However this addon has a Maximum Dimensions setting, which does no resizing, it simply just won't pass the image into the post as an attachment for processing... is this correct?

Is there any logging when an image is too large?
 
Hey, we just had someone contact us about this not being compatible with our Image Optimizer add-on. Took a look to see if there was anything we could do on our end. However, it looks like you're directly inserting attachment data via these queries:

PHP:
                            $db = \XF::db();

                            $db->query("
                                INSERT INTO xf_attachment_data
                                    (user_id, upload_date, filename, file_size, file_hash, width, height, thumbnail_width, thumbnail_height, attach_count)
                                VALUES
                                    (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
                            ", array($currentUserId, $uploadDate, $basename, $fileSize, $filehash, $width, $height, '0', '0', '1'));

                            // get the new data_id number (auto incremented)
                            $dataId = $db->lastInsertId();

                            //#####################################
                            // run SQL query (attachment)
                            //#####################################

                            $db->query("
                                INSERT INTO xf_attachment
                                    (data_id, content_type, content_id, attach_date, temp_hash, unassociated, view_count)
                                VALUES
                                    (?, ?, ?, ?, ?, ?, ?)
                            ", array($dataId, 'post', $postId, $uploadDate, '', '0', '0'));

                            // get the new attachment_id number (auto incremented)
                            $attachmentId = $db->lastInsertId();

also, it looks like it's moving the files into the internal_data and data directories using a combination of mkdir and touch, chmod and file_put_contents. Could you adjust this to use XF's attachment preparer service and their file handler system?
 
Hey, we just had someone contact us about this not being compatible with our Image Optimizer add-on. Took a look to see if there was anything we could do on our end. However, it looks like you're directly inserting attachment data via these queries:

PHP:
                            $db = \XF::db();

                            $db->query("
                                INSERT INTO xf_attachment_data
                                    (user_id, upload_date, filename, file_size, file_hash, width, height, thumbnail_width, thumbnail_height, attach_count)
                                VALUES
                                    (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
                            ", array($currentUserId, $uploadDate, $basename, $fileSize, $filehash, $width, $height, '0', '0', '1'));

                            // get the new data_id number (auto incremented)
                            $dataId = $db->lastInsertId();

                            //#####################################
                            // run SQL query (attachment)
                            //#####################################

                            $db->query("
                                INSERT INTO xf_attachment
                                    (data_id, content_type, content_id, attach_date, temp_hash, unassociated, view_count)
                                VALUES
                                    (?, ?, ?, ?, ?, ?, ?)
                            ", array($dataId, 'post', $postId, $uploadDate, '', '0', '0'));

                            // get the new attachment_id number (auto incremented)
                            $attachmentId = $db->lastInsertId();

also, it looks like it's moving the files into the internal_data and data directories using a combination of mkdir and touch, chmod and file_put_contents. Could you adjust this to use XF's attachment preparer service and their file handler system?

Strange, I would have thought by now all of Andy's addons were adhering to the resource standards. Hopefully it gets resolved soon. :)
 
Had two more tickets over the weekend, this time from XPress having issues:

Code:
ImagickException: unable to open image `internal_data/attachments/11/11875-43f30cf62612cdd6a21ef9f0a8cdb0a6.data': No such file or directory @ error/blob.c/OpenBlob/2712 src/addons/Andy/ConvertImage/Listener.php:523
Generated by: Matt Mar 10, 2019 at 11:37 AM
Stack trace
#0 src/addons/Andy/ConvertImage/Listener.php(523): Imagick->readimage('internal_data/a...')
#1 [internal function]: Andy\ConvertImage\Listener::threadEntityPostSave(Object(ThemeHouse\XPress\XF\Entity\Post))
#2 src/XF/Extension.php(50): call_user_func_array(Array, Array)
#3 src/XF.php(721): XF\Extension->fire('entity_post_sav...', Array, 'XF\\Entity\\Post')
#4 src/XF/Mvc/Entity/Entity.php(1214): XF::fire('entity_post_sav...', Array, 'XF\\Entity\\Post')
#5 src/XF/Mvc/Entity/Entity.php(1202): XF\Mvc\Entity\Entity->save(true, false)
#6 src/XF/Service/Thread/Creator.php(285): XF\Mvc\Entity\Entity->save(true, false)
#7 src/XF/Service/ValidateAndSavableTrait.php(40): XF\Service\Thread\Creator->_save()
#8 src/addons/ThemeHouse/XPress/Service/WordPress/CreateThread.php(60): XF\Service\Thread\Creator->save()
#9 /var/www/fdoc.co.uk/public_html/wp-content/plugins/wp-xpress-plugin/src/XPress.php(716): ThemeHouse\XPress\Service\WordPress\CreateThread->save()
#10 /var/www/fdoc.co.uk/public_html/wp-includes/class-wp-hook.php(288): XPress::{closure}(438)
#11 /var/www/fdoc.co.uk/public_html/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters(NULL, Array)
#12 /var/www/fdoc.co.uk/public_html/wp-includes/plugin.php(465): WP_Hook->do_action(Array)
#13 /var/www/fdoc.co.uk/public_html/wp-includes/post.php(3951): do_action('save_post', 438, Object(WP_Post), true)
#14 /var/www/fdoc.co.uk/public_html/wp-includes/post.php(4028): wp_insert_post(Array, false)
#15 /var/www/fdoc.co.uk/public_html/wp-admin/includes/post.php(405): wp_update_post(Array)
#16 /var/www/fdoc.co.uk/public_html/wp-admin/post.php(218): edit_post()
#17 {main}

This is happening because the Flysystem file handlers are being bypassed, and it's attempting to read/write images to the incorrect directory since the functions aren't being run from within XenForo's directory.
 
Last edited:
@AndyB how long do you need to rectify the issues outlined by @Jake B. above?

Adding your own compression code to your add-on is a fairly lacklustre solution to the originally reported issue.

And it now seems you are writing attachment related things out directly to the filesystem. Since XF 2.0 we have had an abstracted file system which means that data and internal_data may or may not be on the file system anymore.

See the resource standards here. The following points relate to what I'm talking about:
6. Database queries should mostly be performed using the Finder. Where there’s a specific reason not to, database queries must use the default XF database adapter and must use prepared statements.
7. Similarly, add-ons should not bypass Entity objects and should perform reads and writes using these and related objects.
28. Similarly, if XF has any other framework features including (but not limited to) email sending and image manipulation these should be used where practicable.
29. File system operations must use the XF file system (which uses "FlySystem") particularly for files hosted in data, internal_data or code_cache directories.

I'm also aware that many of your other add-ons may fall short of the standards too.

I'm certain that, on their own, your add-ons work wonderfully well in a perfect world. But unfortunately it appears as though a number of your add-ons are now having an adverse interaction with other add-ons which are following the standards correctly.

Please review the standards and see if any of the points may apply to any of your add-ons. If they do, you will need to make changes to these add-ons. If you do not understand what any of the standards mean, you should post in the Dev discussions forum for clarification and assistance.

Going forward, you will have a limited amount of time to rectify code issues reported with your add-ons, and if you are unable to do so then the resources will be deleted.

These rules apply to other authors too, but so far it is only your code that appears to be causing problems.
 
Hi Andy I see this addon along with the TH image optimizer in this error, any thoughts?

Code:
ErrorException: [Image Optimizer] Error received from Kraken for status ID 327: cURL Error: getaddrinfo() thread failed to start
src/XF/Error.php:75
Generated by: xxx
Mar 29, 2019 at 9:01 AM
Stack trace

#0 src/XF.php(187): XF\Error->logError('[Image Optimize...', false)

#1 src/addons/ThemeHouse/ImageOptimizer/ImageOptimizer/Kraken.php(99): XF::logError('[Image Optimize...')

#2 src/addons/ThemeHouse/ImageOptimizer/ImageOptimizer/Kraken.php(82): ThemeHouse\ImageOptimizer\ImageOptimizer\Kraken->krakenFailedResponse(Object(ThemeHouse\ImageOptimizer\Service\ImageOptimizer\Optimize), '[Image Optimize...', true)

#3 src/addons/ThemeHouse/ImageOptimizer/Service/ImageOptimizer/Optimize.php(47): ThemeHouse\ImageOptimizer\ImageOptimizer\Kraken->optimizeImage(Object(ThemeHouse\ImageOptimizer\Service\ImageOptimizer\Optimize))

#4 src/addons/ThemeHouse/ImageOptimizer/ContentHandler/AbstractHandler.php(57): ThemeHouse\ImageOptimizer\Service\ImageOptimizer\Optimize->run()

#5 src/addons/ThemeHouse/ImageOptimizer/ContentHandler/AbstractHandler.php(160): ThemeHouse\ImageOptimizer\ContentHandler\AbstractHandler->optimize(Object(ThemeHouse\ImageOptimizer\Entity\Status))

#6 src/addons/ThemeHouse/ImageOptimizer/ImageOptimizer.php(105): ThemeHouse\ImageOptimizer\ContentHandler\AbstractHandler->createStatusAndOptimize(Object(ThemeHouse\ImageOptimizer\XF\Entity\AttachmentData))

#7 src/addons/ThemeHouse/ImageOptimizer/ImageOptimizer.php(36): ThemeHouse\ImageOptimizer\ImageOptimizer->optimizeEntity('attachment', Object(ThemeHouse\ImageOptimizer\XF\Entity\AttachmentData))

#8 src/addons/ThemeHouse/ImageOptimizer/XF/Service/Attachment/Preparer.php(15): ThemeHouse\ImageOptimizer\ImageOptimizer::eek:ptimize('attachment', Object(ThemeHouse\ImageOptimizer\XF\Entity\AttachmentData))

#9 src/XF/Service/Attachment/Preparer.php(23): ThemeHouse\ImageOptimizer\XF\Service\Attachment\Preparer->insertDataFromFile(Object(XF\FileWrapper), 635255, Array)

#10 src/addons/Andy/ConvertImage/Listener.php(391): XF\Service\Attachment\Preparer->insertAttachment(Object(XF\Attachment\Post), Object(XF\FileWrapper), Object(SV\ReportImprovements\XF\Entity\User), 'c14554c49ed605d...')

#11 [internal function]: Andy\ConvertImage\Listener::threadEntityPostSave(Object(SV\ReportImprovements\XF\Entity\Post))

#12 src/XF/Extension.php(50): call_user_func_array(Array, Array)

#13 src/XF.php(721): XF\Extension->fire('entity_post_sav...', Array, 'XF\\Entity\\Post')

#14 src/XF/Mvc/Entity/Entity.php(1214): XF::fire('entity_post_sav...', Array, 'XF\\Entity\\Post')

#15 src/XF/Mvc/Entity/Entity.php(1202): XF\Mvc\Entity\Entity->save(true, false)

#16 src/XF/Service/Thread/Creator.php(285): XF\Mvc\Entity\Entity->save(true, false)

#17 src/addons/SV/ReportCentreEssentials/XF/Service/Thread/Creator.php(19): XF\Service\Thread\Creator->_save()

#18 src/XF/Service/ValidateAndSavableTrait.php(40): SV\ReportCentreEssentials\XF\Service\Thread\Creator->_save()

#19 src/XF/Pub/Controller/Forum.php(750): XF\Service\Thread\Creator->save()

#20 src/addons/SV/ElasticSearchEssentials/XF/Pub/Controller/Forum.php(54): XF\Pub\Controller\Forum->actionPostThread(Object(XF\Mvc\ParameterBag))

#21 src/XF/Mvc/Dispatcher.php(321): SV\ElasticSearchEssentials\XF\Pub\Controller\Forum->actionPostThread(Object(XF\Mvc\ParameterBag))

#22 src/XF/Mvc/Dispatcher.php(244): XF\Mvc\Dispatcher->dispatchClass('XF:Forum', 'PostThread', Object(XF\Mvc\RouteMatch), Object(SV\ElasticSearchEssentials\XF\Pub\Controller\Forum), NULL)

#23 src/XF/Mvc/Dispatcher.php(100): XF\Mvc\Dispatcher->dispatchFromMatch(Object(XF\Mvc\RouteMatch), Object(SV\ElasticSearchEssentials\XF\Pub\Controller\Forum), NULL)

#24 src/XF/Mvc/Dispatcher.php(50): XF\Mvc\Dispatcher->dispatchLoop(Object(XF\Mvc\RouteMatch))

#25 src/XF/App.php(2177): XF\Mvc\Dispatcher->run()

#26 src/XF.php(390): XF\App->run()

#27 index.php(20): XF::runApp('XF\\Pub\\App')

#28 {main}

Request state

array(4) {

  ["url"] => string(53) "/forums/introductory-physics-homework.153/post-thread"

  ["referrer"] => string(82) "xxx/forums/introductory-physics-homework.153/post-thread"

  ["_GET"] => array(0) {

  }

  ["_POST"] => array(14) {

    ["title"] => string(49) "Find the position of a proton in a E and B field."

    ["custom_fields"] => array(2) {

      ["problemstatement"] => string(14) "(See Attempt)."

      ["equations"] => string(14) "(See Attempt)."

    }

    ["message_html"] => string(1179) "xxx<img src="[MEDIA=imgur]OQ5oJRa[/MEDIA]" style="width: auto;" class="fr-fic fr-dii">xxx<img src="[MEDIA=imgur]dJx7Hx3[/MEDIA]" style="width: auto;" class="fr-fic fr-dii">xxx"

    ["attachment_hash"] => string(32) "51378c31399a4ef79988181791bedc6f"

    ["attachment_hash_combined"] => string(83) "{"type":"post","context":{"node_id":153},"hash":"51378c31399a4ef79988181791bedc6f"}"

    ["tokens_select"] => string(8) "position"

    ["tags"] => string(49) "magnetic field, proton, velocity, helix, position"

    ["watch_thread"] => string(1) "1"

    ["watch_thread_email"] => string(1) "1"

    ["_xfSet"] => array(1) {

      ["watch_thread"] => string(1) "1"

    }

    ["_xfToken"] => string(8) "****"

    ["_xfRequestUri"] => string(53) "/forums/introductory-physics-homework.153/post-thread"

    ["_xfWithData"] => string(1) "1"

    ["_xfResponseType"] => string(4) "json"

  }

}
 
Top Bottom