phpjqueryimagemagickpsduploadcare

Use imagemagick with uploadcare to display thumbnail for PSD, PDF file types


I have a form where users can upload files using uploadcare widget. Once uploaded I can output/show the preview, but only if the file type is image like jpg, png etc. But I need to be able to show for other file types like PSD, PDF as well. I am trying to implement imagemagick for this, but confused how to use it with uploadcare as the widget uses jquery to fetch image cdn. Whereas most tutorial I found online are for php.

You can have a look at the widget snippet in this fiddle: https://jsfiddle.net/kamela101/e6ac6jb4/

$ = uploadcare.jQuery;
  // Create uploaded image list and append additional form fields to each item
  function installWidgetPreviewMultiple(widget, list) {
    widget.onChange(function(fileGroup) {
      list.empty();
      if (fileGroup) {
        $.when.apply(null, fileGroup.files()).done(function() {

          $.each(arguments, function(i, fileInfo) {
            // display file preview
            var $filename = fileInfo.name;// display file name
            var $fileurl = fileInfo.cdnUrl;// get file url
            var $src = fileInfo.cdnUrl + '-/resize/100x100/filename.jpg';// preview image source, resize to 100X100px and jpeg file type
            // append preview and name and form fields to each file uploaded inside thumb_list 
            list.append(
              $('<li class="thumb_list_item"><img src="' + $src+ '" alt="File Preview" class="preview-img">' + '<h4 class="filename">' + $filename + '</h4>' + '<div class="get-layer-wraper"><ul class="get-layer"><li class="layer-name"><label for="white-layer" class="layer-title">White Layer : </label></li><li><input id="white-layer" name="white-layer[]" class="layer" type="number" value="0"></li><li>PX</li></ul><div class="clear"><ul class="get-layer"><li class="layer-name"><label for="adhesive-layer" class="layer-title">Adhesive Layer : </label></li><li><input id="adhesive-layer" name="adhesive-layer[]" class="layer" type="number" value="0"></li><li>PX</li></ul><div class="clear"><ul class="get-layer"><li class="layer-name"><label for="block-layer" class="layer-title">Blocking Layer : </label></li><li><input id="block-layer" name="block-layer[]" class="layer" type="number" value="0"></li><li>PX</li></ul><div class="clear"><ul class="get-layer"><li class="layer-name"><label for="clear-layer" class="layer-title">Clear Layer : </label></li><li><input id="clear-layer" name="clear-layer[]" class="layer" type="number" value="0"></li><li>PX</li></ul></div></li>').appendTo(".thumb_list")
              );
          });
        });
      }
    });
  }
$(function() {
  $('.upload-area').each(function() {
    installWidgetPreviewMultiple(
      uploadcare.MultipleWidget($(this).children('input')),
      $(this).children('.thumb_list')
    );
  });
});

Solution

  • Uploadcare doesn't support PSD and PDF preview functionality as of now. You would have to use a third-party service that allows you to do that.