<p>Following <a href="https://ghijk.co.uk/blog/generate-dynamic-social-share-images-in-craft-cms" rel="nofollow noreferrer">this article</a>, I'm trying to generate an image from html on Entry Save, but I'm getting an error when trying to push a job <em>GenerateSocialCard</em> to the Craft queue.</p>
<p>I'm using the default Module. Here is the code:</p>
<pre><code>Queue::push(new GenerateSocialCard([
  'elementId' =&gt; $element-&gt;id 
]));
</code></pre>
<p>I have GenerateSocialCard.php under modules/jobs with the GenerateSocialCard class defined:</p>
<pre><code>&lt;?php

namespace modules\jobs;

use Craft;
use craft\helpers\App;
use craft\queue\BaseJob;
use Spatie\Browsershot\Browsershot;

class GenerateSocialCard extends BaseJob
{

    public $elementId;

    public function execute($queue)
    {
        Browsershot::url(getenv('PRIMARY_SITE_URL') . '/x/' . $this-&gt;elementId)
            -&gt;setNodeBinary(App::env('NODE_BINARY'))
            -&gt;setNpmBinary(App::env('NPM_BINARY'))
            -&gt;windowSize(1200, 675)
            -&gt;waitUntilNetworkIdle()
            -&gt;save(getcwd() . '/web/img/fakty' . $this-&gt;elementId . '.png');
    }

    protected function defaultDescription(): string
    {
        return Craft::t('app', 'Generate the social card');
    }
}
</code></pre>
<p>I'm still getting an error <em><strong>Class &quot;modules\jobs\GenerateSocialCard&quot; not found</strong></em></p>
<p>Any Ideas?</p>
<p>Thank you!!</p>
<p><strong>Modules folder structure:</strong></p>
<pre><code>modules
  - jobs
    - GenerateSocialCard.php
- Module.php
</code></pre>
<p><strong>Composer.json</strong></p>
<pre><code>&quot;autoload&quot;: {
   &quot;psr-4&quot;: {
     &quot;modules\\&quot;: &quot;modules/&quot;
   }
},
</code></pre>

CC BY-SA 4.0
2023-06-29T09:29:31.310Z
Looks like the autoloader can't find the PHP file with the class in it – can you post your directory structure (especially the `modules/` folder) and your `composer.json` (especially the `autoload` setup)?
MoritzLost
CC BY-SA 4.0
2023-06-29T11:40:13.930Z
@MoritzLost

I edited the question with all the information you requested.
Michal Bulla
CC BY-SA 4.0
2023-06-29T12:31:13.573Z
Hm, that all looks correct … does the error go away when you run `composer dump-autoload`?
MoritzLost
CC BY-SA 4.0
2023-06-29T12:59:31.403Z
@MoritzLost Nope. It didn't help ... I'm still getting the same error.

Btw, I was getting _Class "modules\GenerateSocialCard" not found_, so I tried to add `use modules\jobs\GenerateSocialCard;`, then I got the _Class "modules\jobs\GenerateSocialCard" not found_.
Michal Bulla
<modules>
Class "modules\jobs\GenerateSocialCard" not found
# Class "modules\jobs\GenerateSocialCard" not found

(Asked by: username_0 on 2023-06-29)

Following this article, I'm trying to generate an image from html on Entry Save, but I'm getting an error when trying to push a job GenerateSocialCard to the Craft queue.
I'm using the default Module. Here is the code:
Queue::push(new GenerateSocialCard([
  'elementId' => $element->id 
]));

I have GenerateSocialCard.php under modules/jobs with the GenerateSocialCard class defined:
elementId)
            ->setNodeBinary(App::env('NODE_BINARY'))
            ->setNpmBinary(App::env('NPM_BINARY'))
            ->windowSize(1200, 675)
            ->waitUntilNetworkIdle()
            ->save(getcwd() . '/web/img/fakty' . $this->elementId . '.png');
    }

    protected function defaultDescription(): string
    {
        return Craft::t('app', 'Generate the social card');
    }
}

I'm still getting an error Class "modules\jobs\GenerateSocialCard" not found
Any Ideas?
Thank you!!
Modules folder structure:
modules
  - jobs
    - GenerateSocialCard.php
- Module.php

Composer.json
"autoload": {
   "psr-4": {
     "modules\\": "modules/"
   }
},

**Tags:** modules
> **Comments:**
> **username_1**: Looks like the autoloader can't find the PHP file with the class in it – can you post your directory structure (especially the `modules/` folder) and your `composer.json` (especially the `autoload` setup)?  
> **username_0**: @MoritzLost  I edited the question with all the information you requested.  
> **username_1**: Hm, that all looks correct … does the error go away when you run `composer dump-autoload`?  
> **username_0**: @MoritzLost Nope. It didn't help ... I'm still getting the same error.  Btw, I was getting _Class "modules\GenerateSocialCard" not found_, so I tried to add `use modules\jobs\GenerateSocialCard;`, then I got the _Class "modules\jobs\GenerateSocialCard" not found_.  

---

## 0 answers

