ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* t-degrade.tex
@ 2012-07-27 10:52 Peter Münster
  2012-07-31  7:22 ` t-degrade.tex Jan Kula
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Peter Münster @ 2012-07-27 10:52 UTC (permalink / raw)
  To: ConTeXt users

Hi,

Does it make sense, to port http://modules.contextgarden.net/t-degrade
to mkiv, or is there already an existing solution in ConTeXt to
downsample jpeg-images on the fly?

TIA for any hints,
-- 
           Peter
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: t-degrade.tex
  2012-07-27 10:52 t-degrade.tex Peter Münster
@ 2012-07-31  7:22 ` Jan Kula
  2012-07-31  8:32   ` t-degrade.tex luigi scarso
  2012-07-31 15:04 ` width/height in figure converter (was: t-degrade.tex) Peter Münster
  2012-07-31 22:36 ` t-degrade.tex (solved) Peter Münster
  2 siblings, 1 reply; 5+ messages in thread
From: Jan Kula @ 2012-07-31  7:22 UTC (permalink / raw)
  To: ntg-context

Hi Peter,

On 07/27/2012 12:52 PM, Peter Münster wrote:
> Hi,
>
> Does it make sense, to port http://modules.contextgarden.net/t-degrade
> to mkiv, or is there already an existing solution in ConTeXt to
> downsample jpeg-images on the fly?
>
> TIA for any hints,

There is Luigi's gmwand approach in grph-wnd.lua and something on 
conversions in grph-inc.lua, but I don't know a higher level context 
interface. Anybody else?

Jano

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: t-degrade.tex
  2012-07-31  7:22 ` t-degrade.tex Jan Kula
@ 2012-07-31  8:32   ` luigi scarso
  0 siblings, 0 replies; 5+ messages in thread
From: luigi scarso @ 2012-07-31  8:32 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 713 bytes --]

On Tue, Jul 31, 2012 at 9:22 AM, Jan Kula <jano.kula@gmail.com> wrote:

> Hi Peter,
>
>
> On 07/27/2012 12:52 PM, Peter Münster wrote:
>
>> Hi,
>>
>> Does it make sense, to port http://modules.contextgarden.**net/t-degrade<http://modules.contextgarden.net/t-degrade>
>> to mkiv, or is there already an existing solution in ConTeXt to
>> downsample jpeg-images on the fly?
>>
>> TIA for any hints,
>>
>
> There is Luigi's gmwand approach in grph-wnd.lua and something on
> conversions in grph-inc.lua, but I don't know a higher level context
> interface. Anybody else?
>
>
If I have time I will try to rebuild the module, because it seems that the
bug with libpng is fixed.


-- 
luigi

[-- Attachment #1.2: Type: text/html, Size: 1202 bytes --]

[-- Attachment #2: Type: text/plain, Size: 485 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 5+ messages in thread

* width/height in figure converter (was: t-degrade.tex)
  2012-07-27 10:52 t-degrade.tex Peter Münster
  2012-07-31  7:22 ` t-degrade.tex Jan Kula
@ 2012-07-31 15:04 ` Peter Münster
  2012-07-31 22:36 ` t-degrade.tex (solved) Peter Münster
  2 siblings, 0 replies; 5+ messages in thread
From: Peter Münster @ 2012-07-31 15:04 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Fri, Jul 27 2012, Peter Münster wrote:

> Does it make sense, to port http://modules.contextgarden.net/t-degrade
> to mkiv, or is there already an existing solution in ConTeXt to
> downsample jpeg-images on the fly?

I've played a bit with the converters:

--8<---------------cut here---------------start------------->8---
\startluacode
figures.converters["jpg"] = {
  ["lowres.jpg"] = function(oldname,newname,resolution)
    os.execute"something"
    print(table.serialize(figures.current()))
  end
}
\stopluacode
\starttext
\externalfigure[hacker][width=0.5\textwidth, conversion=lowres.jpg]
\stoptext 
--8<---------------cut here---------------end--------------->8---

2 questions:

- How can I get the width and/or the height of the figure inside the
  function?  "0.5\9extwidth " is not very useful on the lua-side...

- How can I specify a sub-directory where to place the converted images?
  (not so important, just to avoid cluttering the current directory)


TIA for any help,
-- 
           Peter
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: t-degrade.tex (solved)
  2012-07-27 10:52 t-degrade.tex Peter Münster
  2012-07-31  7:22 ` t-degrade.tex Jan Kula
  2012-07-31 15:04 ` width/height in figure converter (was: t-degrade.tex) Peter Münster
@ 2012-07-31 22:36 ` Peter Münster
  2 siblings, 0 replies; 5+ messages in thread
From: Peter Münster @ 2012-07-31 22:36 UTC (permalink / raw)
  To: mailing list for ConTeXt users

[-- Attachment #1: Type: text/plain, Size: 2368 bytes --]

Now I can downsample jpeg-files on the fly, see attached example file.
But I need 2 patches:

1.) To get the width and the height into the name of the file,
    because when the figure dimensions change, there must be a new
    conversion:

--8<---------------cut here---------------start------------->8---
--- grph-inc.lua~	2012-06-05 10:37:01.000000000 +0200
+++ grph-inc.lua	2012-07-31 22:40:39.214426838 +0200
@@ -528,6 +528,9 @@
                     if resolution and resolution ~= "" then -- the order might change
                         newbase = newbase .. "_" .. resolution
                     end
+                    local width = figures.current().request.width
+                    local height = figures.current().request.height
+                    newbase = newbase .. "_" .. width .. "_" .. height
                     --
                     -- see *, we had:
                     --
--8<---------------cut here---------------end--------------->8---


2.) To avoid crap in the width and height options:

--8<---------------cut here---------------start------------->8---
--- grph-inc.mkiv~	2012-07-20 23:26:52.000000000 +0200
+++ grph-inc.mkiv	2012-08-01 00:02:23.851094854 +0200
@@ -293,6 +293,10 @@
    %
    \the\t_grph_include_local_settings
    \dostarttagged\t!image\empty
+   \edef\current_width{\externalfigureparameter\c!width}%
+   \edef\current_height{\externalfigureparameter\c!height}%
+   \def\nocrap##1{\doifnotemptyvalue{##1}{%
+       \the\dimexpr\csname##1\endcsname\relax}}%
    \ctxlua{figures.push {
         name       = "\p_grph_include_name",
         label      = "\p_grph_include_label",
@@ -312,8 +316,8 @@
         resolution = "\externalfigureparameter\c!resolution",
         color      = "\internalspotcolorparent{\externalfigureparameter\c!color}", % hack is needed
         ["repeat"] = "\externalfigureparameter\c!repeat",
-        width      = "\externalfigureparameter\c!width",  % can be crap
-        height     = "\externalfigureparameter\c!height", % can be crap
+        width      = "\nocrap{current_width}",  % no more crap
+        height     = "\nocrap{current_height}", % no more crap
     } }%
    \ctxlua{figures.identify()}%
    % also mode: checkpresense only
--8<---------------cut here---------------end--------------->8---


Hans, could you please patch the files?

Cheers,
-- 
           Peter

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: downsample.tex --]
[-- Type: text/x-tex, Size: 1431 bytes --]

\startluacode
local format = string.format
-- figures.cachepaths.path = "cache" -- should be setup-option
local function sample_down(oldname, newname, resolution)
  local request = figures.current().request
  local width = request.width:sub(1, -3)
  local height = request.height:sub(1, -3)
  if resolution == "" or (width == "" and height == "") then
    print(format("Nothing to do: %s, %s, %s", oldname, newname, resolution))
    return
  end
  local inch = 72.27
  local image = img.scan{filename = oldname}
  local xy = image.xsize / image.ysize
  if width == "" then
    width = height * xy
  end
  if height == "" then
    height = width / xy
  end
  local xsize = resolution * width / inch
  local ysize = resolution * height / inch
  if xsize < image.xsize or ysize < image.ysize then
    local s = format("gm convert -resize %dx%d %s %s",
                     xsize, ysize, oldname, newname)
    print("Conversion: " .. s)
    os.execute(s)
  else
    print(format("Nothing to do: %s, %s, %s", oldname, newname, resolution))
    print(format("xsize = %d, ysize = %d", xsize, ysize))
  end
end

figures.converters.jpg = figures.converters.jpg or {}
figures.converters.jpg["lowres.jpg"] = sample_down
\stopluacode

\starttext
\setupexternalfigures[resolution=50, conversion=lowres.jpg]
\externalfigure[hacker][width=0.5\textwidth]
\setupexternalfigures[resolution=10]
\externalfigure[hacker][width=0.5\textwidth]
\stoptext

[-- Attachment #3: Type: text/plain, Size: 485 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-07-31 22:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-27 10:52 t-degrade.tex Peter Münster
2012-07-31  7:22 ` t-degrade.tex Jan Kula
2012-07-31  8:32   ` t-degrade.tex luigi scarso
2012-07-31 15:04 ` width/height in figure converter (was: t-degrade.tex) Peter Münster
2012-07-31 22:36 ` t-degrade.tex (solved) Peter Münster

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).