• I am hosting a wordpress site on ubuntu with apache and i am not able to upload SVG file for a site logo. When I try i get the “Post-processing of the image failed likely because the server is busy or does not have enough resources. Uploading a smaller image may help. Suggested maximum size is 2500 pixels.” error.

    I have installed several SVG plugins (Disable “BIG image” Threshold, Disable Real MIME Check, Safe SVG, and SVG Support) and have ensured the SVG file has the needed header info at the beginning of the file. I have also tried adding the below code to the themes functions.php file but that still did not fix the issue.

    // Allow SVG
    add_filter( 'wp_check_filetype_and_ext', function($data, $file, $filename, $mimes) {
    
      global $wp_version;
      if ( $wp_version !== '4.7.1' ) {
         return $data;
      }
    
      $filetype = wp_check_filetype( $filename, $mimes );
    
      return [
          'ext'             => $filetype['ext'],
          'type'            => $filetype['type'],
          'proper_filename' => $data['proper_filename']
      ];
    
    }, 10, 4 );
    
    function cc_mime_types( $mimes ){
      $mimes['svg'] = 'image/svg+xml';
      return $mimes;
    }
    add_filter( 'upload_mimes', 'cc_mime_types' );
    
    function fix_svg() {
      echo '<style type="text/css">
            .attachment-266x266, .thumbnail img {
                 width: 100% !important;
                 height: auto !important;
            }
            </style>';
    }
    add_action( 'admin_head', 'fix_svg' );
    • This topic was modified 3 years, 9 months ago by bcworkz. Reason: code fixed
Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Just this alone

    function cc_mime_types( $mimes ){
      $mimes['svg'] = 'image/svg+xml';
      return $mimes;
    }
    add_filter( 'upload_mimes', 'cc_mime_types' );

    should allow uploading to the media library and insertion into post content. Much of the UI elements related to images will not work because it’s not a raster image but you can at least insert the file reference and style it with CSS.

    The fix_svg() function in your code may or may not be meaningful. As it’s only for the admin area, I’m unsure what it would be applied to.

    The function added to “wp_check_filetype_and_ext” filter is ineffective for most installations because of the version check. I’m not sure the whole thing is necessary unless there is some quirk specifically for v4.7.1.

Viewing 1 replies (of 1 total)
  • The topic ‘Unable to upload SVG’ is closed to new replies.