[cl-gd-devel] Resizing Images
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.
On Sun, 23 Sep 2007 20:31:10 +0300, Volkan YAZICI <yazicivo@ttnet.net.tr> wrote:
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?
Did you try the equivalent in C? It might be a problem in GD itself and not in CL-GD.
Edi Weitz <edi@agharta.de> writes:
On Sun, 23 Sep 2007 20:31:10 +0300, Volkan YAZICI <yazicivo@ttnet.net.tr> wrote:
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?
Did you try the equivalent in C? It might be a problem in GD itself and not in CL-GD.
Umm... Also libgd provides identical output. (Code is attached.) Seems like I'm missing something. Any ideas? How do you resize your images? Regards.
Volkan YAZICI <yazicivo@ttnet.net.tr> writes:
... dsth = (unsigned int) (scale * srch); dstip = gdImageCreate(dstw, dsth);
Replacing gdImageCreate() with gdImageCreateTrueColor() solved the problem. (A similar approach is applicable for :TRUE-COLOR key of WITH-IMAGE macro as well.) Regards.
participants (2)
-
Edi Weitz -
Volkan YAZICI