Skip to content

Commit

Permalink
fix!: map BMP and TIFF extensions to the proper MIME types
Browse files Browse the repository at this point in the history
Remove the WBMP image format from PDF to Image
  • Loading branch information
sbplat committed Dec 24, 2023
1 parent 914dd0a commit 995a926
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package stirling.software.SPDF.controller.api.converters;

import java.io.IOException;
import java.net.URLConnection;

import org.apache.pdfbox.rendering.ImageType;
import org.slf4j.Logger;
Expand All @@ -23,6 +24,7 @@
import stirling.software.SPDF.model.api.converters.ConvertToPdfRequest;
import stirling.software.SPDF.utils.PdfUtils;
import stirling.software.SPDF.utils.WebResponseUtils;

@RestController
@RequestMapping("/api/v1/convert")
@Tag(name = "Convert", description = "Convert APIs")
Expand Down Expand Up @@ -89,15 +91,7 @@ public ResponseEntity<byte[]> convertToPdf(@ModelAttribute ConvertToPdfRequest r
}

private String getMediaType(String imageFormat) {
if (imageFormat.equalsIgnoreCase("PNG"))
return "image/png";
else if (imageFormat.equalsIgnoreCase("JPEG") || imageFormat.equalsIgnoreCase("JPG"))
return "image/jpeg";
else if (imageFormat.equalsIgnoreCase("GIF"))
return "image/gif";
else
return "application/octet-stream";
String mimeType = URLConnection.guessContentTypeFromName("." + imageFormat);
return mimeType.equals("null") ? "application/octet-stream" : mimeType;
}


}
1 change: 0 additions & 1 deletion src/main/resources/templates/convert/pdf-to-img.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ <h2 th:text="#{pdfToImage.header}"></h2>
<option value="gif">GIF</option>
<option value="tiff">TIFF</option>
<option value="bmp">BMP</option>
<option value="wbmp">WBMP</option>
</select>
</div>
<div class="mb-3">
Expand Down

0 comments on commit 995a926

Please sign in to comment.