title: Handling only images with thumbnail creator Azure Function
body: <p>I created a simple Azure Function that creates thumbnails for images uploaded to a container on Azure which gets triggered by a <code>BlobTrigger</code>.</p>
  <p>It's working fine but because my container has both image files as well as other types e.g. PDF, Excel, Word, etc., the function gets triggered by all these files.</p>
  <p>I thought I could address this by making sure that we only process image files using the code below. It kind of works because it only processes image files but it still seems to create placeholder blobs for other file types in the target container.</p>
  <p>For example, if it detects a file named <code>myfile.pdf</code> in the source container, it still creates a <code>myfile.pdf</code> in the target container but it's 0 Bytes.</p>
  <p>How do I make sure that a non-image files completely get skipped and not even create placeholders in my target container?</p>
  <pre><code>[FunctionName(&quot;ImageResizer&quot;)]
  public async Task Run([BlobTrigger(&quot;my-source-container/{name}&quot;, Connection = &quot;myconnection&quot;)] Stream input, string name, [Blob(&quot;my-thumbnails-container/{name}&quot;, FileAccess.Write, Connection = &quot;myconnection&quot;)] Stream outputBlob, ILogger log)
  {
      try
      {
          var fileExtension = FileUtils.GetFileExtension(name);
          if (!string.IsNullOrEmpty(fileExtension))
          {
              if (fileExtension.ToLower() == &quot;png&quot; || fileExtension.ToLower() == &quot;jpg&quot; || fileExtension.ToLower() == &quot;jpeg&quot;)
              {
                  using (var image = Image.Load(input))
                  {
                      image.Mutate(x =&gt; x.Resize(new ResizeOptions
                      {
                          Size = new Size(150, 150),
                          Mode = ResizeMode.Crop
                      }));
  
                      using (var ms = new MemoryStream())
                      {
                          if(fileExtension.ToLower() == &quot;png&quot;)
                              await image.SaveAsPngAsync(outputBlob);
                          else if(fileExtension.ToLower() == &quot;jpg&quot; || fileExtension.ToLower() == &quot;jpeg&quot;)
                              await image.SaveAsJpegAsync(outputBlob);
                      }
                  }
  
                  log.LogInformation($&quot;C# Blob trigger function Processed blob\n Name:{name} \n Size: {input.Length} Bytes&quot;);
             }
           }
       }
       catch (Exception ex)
       {
           log.LogInformation(ex.Message, null);
       }
  }
  </code></pre>