How to get image thumbnails

For help and support with PS3 Media Server in general
Forum rules
Please make sure you follow the Problem Reporting Guidelines before posting if you want a reply.

How to get image thumbnails

Postby vinaykagarwal » Sat Apr 11, 2009 10:06 pm

I am not able to get thumbnails for the images but I can get them just fine for AVI files. I just installed the latest version on Windows XP/SP3. Part of a content directory response is show below. As you can see, the AVI item has thumbnail/albumart but not the image item. How do I get thumbnail for image items? Thanks in advance.

Code: Select all
    <item
        id = "0$0$1$1$4$6$3$7$4$11"
        parentID = "0$0$1$1$4$6$3$7$4"
        restricted = "true">
        <dc:title>011.JPG</dc:title>
        <res
            xmlns:dlna = "urn:schemas-dlna-org:metadata-1-0/"
            protocolInfo = "http-get:*:image/jpeg:DLNA.ORG_OP=01"
            size = "2651068"
            resolution = "2304x3072">http://192.168.1.103:5001/get/0$0$1$1$4$6$3$7$4$11/011.JPG</res>
        <dc:date>2008-07-14T14:04:03</dc:date>
        <upnp:class>object.item.imageItem.photo</upnp:class>
    </item>
    <item
        id = "0$0$1$1$4$6$3$7$4$12"
        parentID = "0$0$1$1$4$6$3$7$4"
        restricted = "true">
        <dc:title>012.AVI</dc:title>
        <res
            xmlns:dlna = "urn:schemas-dlna-org:metadata-1-0/"
            protocolInfo = "http-get:*:video/x-divx:DLNA.ORG_PN=AVI;DLNA.ORG_OP=01"
            size = "13865660"
            duration = "00:00:07.430"
            resolution = "640x480"
            bitrate = "1910016"
            nrAudioChannels = "1"
            sampleFrequency = "44100">http://192.168.1.103:5001/get/0$0$1$1$4$6$3$7$4$12/012.AVI</res>
        <upnp:albumArtURI xmlns:dlna = "urn:schemas-dlna-org:metadata-1-0/" dlna:profileID = "PNG_TN">http://192.168.1.103:5001/get/0$0$1$1$4$6$3$7$4$12/thumbnail0000012.AVI</upnp:albumArtURI>
        <dc:date>2008-07-15T11:13:05</dc:date>
        <upnp:class>object.item.videoItem</upnp:class>
    </item>
vinaykagarwal
 
Posts: 6
Joined: Thu Apr 09, 2009 6:24 pm

Re: How to get image thumbnails

Postby shagrath » Sun Apr 12, 2009 12:29 pm

the ps3 retrieves automatically the image based on the url and make the thumbnail, so no need for Album Art property
shagrath
Project Lead
 
Posts: 2667
Joined: Wed Jan 14, 2009 1:39 pm

Re: How to get image thumbnails

Postby vinaykagarwal » Sun Apr 12, 2009 2:17 pm

I am trying to emulate PS3 (only for media) on a device with far less resources than PS3. PS3 Media Server sees this device as a PS3 and works well. My device doesn't have memory or storage to save 30-40 images where size can be as large as 10MB or more.

Is there any setting that I can enable on PS3 Media Server so that it generates thumbnails for images?
vinaykagarwal
 
Posts: 6
Joined: Thu Apr 09, 2009 6:24 pm

Re: How to get image thumbnails

Postby shagrath » Sun Apr 12, 2009 2:43 pm

no, maybe I will add this later
shagrath
Project Lead
 
Posts: 2667
Joined: Wed Jan 14, 2009 1:39 pm

Re: How to get image thumbnails

Postby vinaykagarwal » Sat Apr 25, 2009 12:33 am

Attached is patch (to version 328) to generate image thumbnails using ImageMagick convert (binaries not included in patch). Modified code works fine on Windows Vista and XP. It has not been tested on Mac or Linux. ImageMagick license seems to be compatible with GPL2 as well. Hope it is useful.

Vinay Agarwal
Attachments
imagethumb.zip
Patch excludes binaries (convert from ImageMagick) for each platform
(2.04 KiB) Downloaded 61 times
vinaykagarwal
 
Posts: 6
Joined: Thu Apr 09, 2009 6:24 pm

Re: How to get image thumbnails

Postby whome » Sat Apr 25, 2009 7:11 am

I think Java (javax.imageio.*) classes can create thumbnails fine, I prefer less native dependencies and more pure-java approach.
Code: Select all
   /**
    * Scale to given canvas size.
    * @param image         original image
    * @param thumbWidth   new canvas width
    * @param thumbHeight   new canvas height
    * @param keepAspectRatio   keep aspect ratio of the original image
    * @param center      center scaled image to new canvas
    * @param bgColor      background color of new canvas
    * @return
    */
   public static BufferedImage scaleToSize(BufferedImage image,
         int thumbWidth, int thumbHeight, boolean keepAspectRatio, boolean center,
         Color bgColor) {
      int w, h;
      if (keepAspectRatio) {
         double thumbRatio = (double)thumbWidth / (double)thumbHeight;
          int imageWidth = image.getWidth();
          int imageHeight = image.getHeight();
          double imageRatio = (double)imageWidth / (double)imageHeight;
          if (thumbRatio < imageRatio) {
             w = thumbWidth;
             h = (int)(thumbWidth / imageRatio);             
          } else {
             w = (int)(thumbHeight * imageRatio)+1;
             h = thumbHeight;
          }      
      } else {
         w = thumbWidth; h = thumbHeight;
      }
      
      // better quality scaling available?
      // http://today.java.net/pub/a/today/2007/04/03/perils-of-image-getscaledinstance.html
      Image imageAWT = image.getScaledInstance(w, h, Image.SCALE_SMOOTH);
      
      BufferedImage newImage = new BufferedImage(thumbWidth, thumbHeight, image.getType());
      Graphics2D g = newImage.createGraphics();

      if (bgColor != null) {
         g.setColor(bgColor);
         g.fillRect(0, 0, thumbWidth, thumbHeight);
      }
      
      if (center) {
         int x = (thumbWidth - w)/2;
         int y = (thumbHeight - h)/2;
         g.drawImage(imageAWT, x, y, null);
      } else {
         g.drawImage(imageAWT, 0, 0, null);
      }
      
      newImage.flush();
      g.dispose();
      return newImage;
   }

   /**
    * Create BufferedImage from Image, possible convert to INT_RGB (jpeg) or INT_ARGB (png) types.
    * @param image   original image
    * @param type   type of new BufferedImage.TYPE_XXXX type
    * @return      
    */
   public static BufferedImage toBufferedImage(Image image, int type, Color bgColor) {
      if (image instanceof BufferedImage && ((BufferedImage)image).getType() == type)
         return (BufferedImage)image;

      int width = image.getWidth(null);
      int height = image.getHeight(null);
      BufferedImage imageNew = new BufferedImage(width, height, type);
      Graphics2D g = imageNew.createGraphics();
      if (bgColor != null) {
         g.setColor(bgColor);
         g.fillRect(0, 0, width, height);
      }
      g.drawImage(image, 0, 0, null);
      g.dispose();
      imageNew.flush();
      return imageNew;
   }   
whome
 
Posts: 113
Joined: Tue Jan 20, 2009 12:26 am

Re: How to get image thumbnails

Postby vinaykagarwal » Sat Apr 25, 2009 4:34 pm

I am OK with java based image scaling. I chose ImageMagick convert simply because it can also be used to create high quality scaled images that may be useful for some hand held devices.
vinaykagarwal
 
Posts: 6
Joined: Thu Apr 09, 2009 6:24 pm

Is there a bug in RealFile class?

Postby vinaykagarwal » Sat Apr 25, 2009 6:29 pm

Even after having non-null valid "thumb" field for image DLNAMediaInfo, I noticed that PMS was serving the original image (which can be very large) as the thumbnail. It is because it is looking for the files with image extensions even in the original image folder before looking at the "thumb" data of DLNAMediaInfo. For image objects, it always finds the original image and, therefore, serves it as the thumbnail. By commenting the two lines that allow it to search in the original image folder, it does serve the correct thumbnail. Should it be looking in the original folder?

Code: Select all
   public InputStream getThumbnailInputStream() throws IOException {
      File cachedThumbnail = null;
      if (getParent() != null && getParent() instanceof RealFile) {
         cachedThumbnail = ((RealFile) getParent()).potentialCover;
         if (cachedThumbnail == null) {
            File thumbFolder = null;
            if (StringUtils.isNotBlank(PMS.getConfiguration().getAlternateThumbFolder())) {
               thumbFolder = new File(PMS.getConfiguration().getAlternateThumbFolder());
               if (!thumbFolder.exists() || !thumbFolder.isDirectory())
                  thumbFolder = null;
            }
            //if (thumbFolder == null)
            //   thumbFolder = file.getParentFile();
            cachedThumbnail = FileUtil.getFileNameWitNewExtension(thumbFolder, file, "jpg");
            if (cachedThumbnail == null)
               cachedThumbnail = FileUtil.getFileNameWitNewExtension(thumbFolder, file, "png");
            if (cachedThumbnail == null)
               cachedThumbnail = FileUtil.getFileNameWitAddedExtension(thumbFolder, file, ".cover.jpg");
            if (cachedThumbnail == null)
               cachedThumbnail = FileUtil.getFileNameWitAddedExtension(thumbFolder, file, ".cover.png");
         }
      }
      boolean hasAlreadyEmbeddedCoverArt = getType() == Format.AUDIO && media != null && media.thumb != null;
      if (cachedThumbnail != null && !hasAlreadyEmbeddedCoverArt)
         return new FileInputStream(cachedThumbnail);
      else if (media != null && media.thumb != null)
         return media.getThumbnailInputStream();
      else return super.getThumbnailInputStream();
   }
vinaykagarwal
 
Posts: 6
Joined: Thu Apr 09, 2009 6:24 pm

Re: How to get image thumbnails

Postby vinaykagarwal » Sun Apr 26, 2009 1:54 am

Updated patch - checks for working direct to be present (binaries not included)
Attachments
imagethumb2.zip
(2.06 KiB) Downloaded 44 times
vinaykagarwal
 
Posts: 6
Joined: Thu Apr 09, 2009 6:24 pm


Return to General Help and Support

Who is online

Users browsing this forum: Yahoo [Bot] and 14 guests