[cl-gd-devel] Resizing Images

Volkan YAZICI yazicivo at ttnet.net.tr
Sun Sep 23 17:31:10 UTC 2007


Hi,

While trying to resize images, using COPY-IMAGE, there occurs serious
color losses. Here is an example code snippet to re-produce the
problem:

(cl-gd:with-image-from-file (src "/tmp/src.jpg" :jpeg)
  (let* ((src-w (cl-gd:image-width src))
	 (src-h (cl-gd:image-height src))
	 (dst-w (truncate (/ src-w 2)))   ; WIDTH /2
	 (dst-h (truncate (/ src-h 2))))  ; HEIGHT/2
    (cl-gd:with-image (dst dst-w dst-h)
      ;; Set transparent color, if any.
      (let ((transparent-color (cl-gd:transparent-color src)))
        (if transparent-color
            (destructuring-bind (red green blue alpha)
                (cl-gd:color-components transparent-color :image src)
              (setf (cl-gd:transparent-color dst)
                    (cl-gd:allocate-color red green blue
                                          :alpha alpha
                                          :image dst)))))
      ;; Copy source scaled onto the destination.
      (cl-gd:copy-image src dst 0 0 0 0
			(cl-gd:image-width src)
			(cl-gd:image-height src)
			:resample t
			:resize t
			:dest-width dst-w
			:dest-height dst-h)
      ;; Output result.
      (cl-gd:write-image-to-file "/tmp/dst.jpg"
                                 :type :jpeg
                                 :image dst
                                 :if-exists :supersede))))

Can anybody spot the problem in the above code? (Removing the part
that sets the transparent color doesn't make any difference.) How do
you resize images in cl-gd?


Regards.



More information about the Cl-gd-devel mailing list