Answers.Body: <p>Started using <a href="https://github.com/aelvan/Imager-Craft" rel="nofollow noreferrer">imager</a> and no longer have the problem. It's not a real answer to the question but it solves the problem.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-14T09:00:08.087Z
Answers.LastActivityDate: 2017-07-14T09:00:08.087Z
Answers.UserDisplayName: mrsmn
Answers.Body: <p>For what it's worth, I also had his issue, turned to imager, which gave me some more useful error messages as to my root cause of the issue:</p>
  
  <p>You may need to make sure that the path to the asset file is complete, not just relative to the site base. So for instance, a base path of <code>./assets</code> works fine for standard purposes, but appears no use for transforming images, you would need <code>http://site/assets</code>.</p>
  
  <p>If your setting a base path in config, you can use something like</p>
  
  <pre><code>'environmentVariables' =&gt; array(
      'assetsBaseUrl' =&gt; '/assets',
      'assetsBasePath' =&gt; "{$_SERVER['DOCUMENT_ROOT']}/assets",
  ),
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-24T09:43:35.970Z
Answers.Text: FWIW, this was the issue for me too. Fixed the path and it fixed the problem.
Answers.UserDisplayName: Mike Pierce
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-11-04T23:10:48.257Z
Answers.Text: Pretty much the issue I experienced too, thanks dude! For anyone else running Craft CMS on IIS in a Windows server, additionally the "basePath" settings seem to follow the slash rule native to the environment being ran in. (So in my case I was originally following Linux forward slash for directories, but because I was on Windows in IIS, I needed to use the backslash instead for my directories.)
Answers.UserDisplayName: J.D.
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-27T15:53:33.207Z
Answers.LastActivityDate: 2017-07-27T15:53:33.207Z
Answers.UserDisplayName: Toby Stokes
Body: <p>EDIT 3: Started using <a href="https://github.com/aelvan/Imager-Craft" rel="nofollow noreferrer">imager</a> and no longer have the problem. It's not a real answer to the problem but solves the problem.</p>
  
  <hr>
  
  <p>This is the situation that has me pulling my hairs... I've looked at other related Q&amp;A's but can't seem to distill a solution for the issue I'm facing. </p>
  
  <p>I'm trying to apply an image transform but I get a link like <code>/cpresources/404?x=TBKkjeyyP</code> returned. Also, no image is being generated. </p>
  
  <p>Files can be uploaded trough the backend just fine, can be linked to an entry and can be shown without applying the transform.</p>
  
  <p>Any pointers as to what is going wrong? I'll gladly provide additional information if/when needed. </p>
  
  <p>My setup is as follows:</p>
  
  <ul>
  <li>Using Craft CMS 2.6.2986 on apache</li>
  <li>3 locales configured (nl, en, fr)</li>
  <li>local storage (File System Path: <code>uploads/</code>&amp; url:  <code>{baseUrl}uploads/</code>)</li>
  <li>relevant config below (using process described <a href="https://github.com/nystudio107/craft-multi-environment" rel="nofollow noreferrer">here</a>)</li>
  </ul>
  
  <p>General config: </p>
  
  <pre><code>// All environments
  '*' =&gt; array(
      'omitScriptNameInUrls' =&gt; true,
      'overridePhpSessionLocation' =&gt; true,
      'usePathInfo' =&gt; true,
      'cacheDuration' =&gt; false,
      'useEmailAsUsername' =&gt; true,
      'generateTransformsBeforePageLoad' =&gt; true,
      'siteUrl' =&gt; array(
          'nl' =&gt; getenv('CRAFTENV_SITE_URL').'nl/',
          'fr' =&gt; getenv('CRAFTENV_SITE_URL').'fr/',
          'en' =&gt; getenv('CRAFTENV_SITE_URL').'en/',
      ),
      'craftEnv' =&gt; CRAFT_ENVIRONMENT,
      'environmentVariables' =&gt; array(
          'baseUrl'  =&gt; getenv('CRAFTENV_BASE_URL'),
          'basePath' =&gt; getenv('CRAFTENV_BASE_PATH'),
      ),
      // development environment
      'development'  =&gt; array(
          'devMode' =&gt; true,
          'enableTemplateCaching' =&gt; false,
          'allowAutoUpdates' =&gt; true,
      );
  );
  </code></pre>
  
  <p>Relevant CRAFT_ENV settings:</p>
  
  <pre><code>'SITE_URL' =&gt; $protocol . $_SERVER['HTTP_HOST'] . '/',
  
  'BASE_URL' =&gt; $protocol . $_SERVER['HTTP_HOST'] . '/',
  
  'BASE_PATH' =&gt; realpath(dirname(__FILE__)) . '/www/',
  </code></pre>
  
  <p>EDIT: Part of the code applying the transform:</p>
  
  <pre><code>{% set thumb = blog.previewImage.first() %}
  {% if thumb %}
      &lt;img src="{{ thumb.getUrl("blogPreview") }}" width="{{ thumb.getWidth("blogPreview") }}" height="{{ thumb.getHeight("blogPreview") }}"&gt;                     
  {% endif %}
  </code></pre>
  
  <p>EDIT 2: relevant log entries</p>
  
  <blockquote>
    <p>Level warning
    Category    application
    Message [Forced] Image “gasmeters.png” could not be found.</p>
    
    <p>Level trace
    Category    system.db.CDbCommand
    Message Executing SQL: DELETE FROM <code>craft_assettransformindex</code> WHERE id = :id. Bound with :id='70'</p>
  </blockquote>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-07-13T11:34:43.920Z
Comments.Text: Show us how do you apply image transform
Comments.UserDisplayName: Krzysztof Boduch
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-07-13T11:54:50.127Z
Comments.Text: Done, see main question
Comments.UserDisplayName: mrsmn
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-07-13T12:46:19.240Z
Comments.Text: Your 404 is being generated here https://github.com/craftcms/cms/blob/2.6.2986/src/services/AssetsService.php#L1026. you must read logs. It might be file permissions.
Comments.UserDisplayName: Krzysztof Boduch
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-07-13T12:59:41.927Z
Comments.Text: Added the relevant log entries, from what I can see,  craft fails to get the file, but I have no clue why...
Comments.UserDisplayName: mrsmn
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-07-13T13:06:51.017Z
Comments.Text: I was able to reproduce this by removing image directly from filesystem. Assets page still shows image preview, but when I try to view image 404 is returned. Same when I try call transformation with broken asset file. Find this gasmeters.png in assets page and reupload it
Comments.UserDisplayName: Krzysztof Boduch
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-07-13T13:10:42.390Z
Comments.Text: The file was still showing in assets interface, still available without the transform, and still viewable when accessing it from the assets interface. 
  
  I deleted the file, reuploaded & relinked the file to the entry but sadly the problem persists.
Comments.UserDisplayName: mrsmn
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-07-13T13:24:40.527Z
Comments.Text: I ran out of ideas, sorry. You can always run debug and see what happens line by line.
Comments.UserDisplayName: Krzysztof Boduch
Tags: <templating><image-transforms>
Title: Applying an image transform returns a 404 cpresources URL
ThreadText: # Applying an image transform returns a 404 cpresources URL
  
  (Asked by: username_0 on 2017-07-13)
  
  EDIT 3: Started using [imager](https://github.com/aelvan/Imager-Craft) and no longer have the problem. It's not a real answer to the problem but solves the problem.
  
  ---
  
  This is the situation that has me pulling my hairs... I've looked at other related Q&A's but can't seem to distill a solution for the issue I'm facing.
  
  I'm trying to apply an image transform but I get a link like `/cpresources/404?x=TBKkjeyyP` returned. Also, no image is being generated.
  
  Files can be uploaded trough the backend just fine, can be linked to an entry and can be shown without applying the transform.
  
  Any pointers as to what is going wrong? I'll gladly provide additional information if/when needed.
  
  My setup is as follows:
  
  * Using Craft CMS 2.6.2986 on apache
  * 3 locales configured (nl, en, fr)
  * local storage (File System Path: `uploads/`& url: `{baseUrl}uploads/`)
  * relevant config below (using process described [here](https://github.com/nystudio107/craft-multi-environment))
  
  General config:
  
  ```
  // All environments
  '*' => array(
      'omitScriptNameInUrls' => true,
      'overridePhpSessionLocation' => true,
      'usePathInfo' => true,
      'cacheDuration' => false,
      'useEmailAsUsername' => true,
      'generateTransformsBeforePageLoad' => true,
      'siteUrl' => array(
          'nl' => getenv('CRAFTENV_SITE_URL').'nl/',
          'fr' => getenv('CRAFTENV_SITE_URL').'fr/',
          'en' => getenv('CRAFTENV_SITE_URL').'en/',
      ),
      'craftEnv' => CRAFT_ENVIRONMENT,
      'environmentVariables' => array(
          'baseUrl'  => getenv('CRAFTENV_BASE_URL'),
          'basePath' => getenv('CRAFTENV_BASE_PATH'),
      ),
      // development environment
      'development'  => array(
          'devMode' => true,
          'enableTemplateCaching' => false,
          'allowAutoUpdates' => true,
      );
  );
  
  ```
  
  Relevant CRAFT\_ENV settings:
  
  ```
  'SITE_URL' => $protocol . $_SERVER['HTTP_HOST'] . '/',
  
  'BASE_URL' => $protocol . $_SERVER['HTTP_HOST'] . '/',
  
  'BASE_PATH' => realpath(dirname(__FILE__)) . '/www/',
  
  ```
  
  EDIT: Part of the code applying the transform:
  
  ```
  {% set thumb = blog.previewImage.first() %}
  {% if thumb %}
      <img src="{{ thumb.getUrl("blogPreview") }}" width="{{ thumb.getWidth("blogPreview") }}" height="{{ thumb.getHeight("blogPreview") }}">                     
  {% endif %}
  
  ```
  
  EDIT 2: relevant log entries
  
  > Level warning
  > Category application
  > Message [Forced] Image “gasmeters.png” could not be found.
  >
  > Level trace
  > Category system.db.CDbCommand
  > Message Executing SQL: DELETE FROM `craft_assettransformindex` WHERE id = :id. Bound with :id='70'
  
  **Tags:** templating, image-transforms
  
  > **Comments:**
  > **username_1**: Show us how do you apply image transform  
  > **username_0**: Done, see main question  
  > **username_1**: Your 404 is being generated here https://github.com/craftcms/cms/blob/2.6.2986/src/services/AssetsService.php#L1026. you must read logs. It might be file permissions.  
  > **username_0**: Added the relevant log entries, from what I can see,  craft fails to get the file, but I have no clue why...  
  > **username_1**: I was able to reproduce this by removing image directly from filesystem. Assets page still shows image preview, but when I try to view image 404 is returned. Same when I try call transformation with broken asset file. Find this gasmeters.png in assets page and reupload it  
  > **username_0**: The file was still showing in assets interface, still available without the transform, and still viewable when accessing it from the assets interface.   I deleted the file, reuploaded & relinked the file to the entry but sadly the problem persists.  
  > **username_1**: I ran out of ideas, sorry. You can always run debug and see what happens line by line.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2017-07-14. Score: 1 | Accepted answer
  
  Started using [imager](https://github.com/aelvan/Imager-Craft) and no longer have the problem. It's not a real answer to the question but it solves the problem.
  
  
  ---
  
  ### Answer by username_2 on 2017-07-27. Score: 4
  
  For what it's worth, I also had his issue, turned to imager, which gave me some more useful error messages as to my root cause of the issue:
  
  You may need to make sure that the path to the asset file is complete, not just relative to the site base. So for instance, a base path of `./assets` works fine for standard purposes, but appears no use for transforming images, you would need `http://site/assets`.
  
  If your setting a base path in config, you can use something like
  
  ```
  'environmentVariables' => array(
      'assetsBaseUrl' => '/assets',
      'assetsBasePath' => "{$_SERVER['DOCUMENT_ROOT']}/assets",
  ),
  
  ```
  
  > **Comments:**
  > **username_3**: FWIW, this was the issue for me too. Fixed the path and it fixed the problem.  
  > **username_4**: Pretty much the issue I experienced too, thanks dude! For anyone else running Craft CMS on IIS in a Windows server, additionally the "basePath" settings seem to follow the slash rule native to the environment being ran in. (So in my case I was originally following Linux forward slash for directories, but because I was on Windows in IIS, I needed to use the backslash instead for my directories.)  
  
  ---
  
  