| View previous topic :: View next topic |
| Author |
Message |
Rubes_sw Valued Contributor


Joined: 11 Jun 2001 Posts: 625 Location: Northern Ireland
|
Posted: Thu Oct 07, 2004 8:19 am Post subject: maintain aspect ratio |
|
|
Anyone any code lying around for maintain aspect ratio
I want to use vdsconv.dll to convert images to a set size, but i want to keep the aspect ratio, I know it would invlove a bit of maths etc.
Any ideas?
Nathan |
|
| Back to top |
|
 |
bbelcher Contributor

Joined: 30 Jul 2002 Posts: 172
|
Posted: Thu Oct 07, 2004 1:28 pm Post subject: |
|
|
I use this code to resize images to specific parameters before I print them. I hope this helps and is not to confusing.
| Code: |
if @null(%%printpix)
info Nothing to PRINT. Please load a graphic first.
goto loop
else
end
rem %%picg = %%curdirtemp\%%pic
%%imgheight = @CONVERT(IMGHEIGHT,%%printpix)
%%imgwidth = @CONVERT(IMGWIDTH,%%printpix)
%%aspectratio = @FDIV(%%imgwidth,%%imgheight)
rem if image height is greater the width i.e. portrait. Also image is sized to fit into a 950 pix tall area.
if @greater(%%imgheight,%%imgwidth)
if @greater(%%imgheight,951)
rem info %%aspectratio %%imgwidth %%imgheight
%%downscalewidth = @FMUL(950,%%aspectratio)
%%printwidth = %%downscalewidth
%%printheight = 950
else
%%upscalewidth = @FMUL(950,%%aspectratio)
%%printwidth = %%upscalewidth
%%printheight = 950
end
end
rem if image width is greter then height i.e. landscape Also image is sized to fit into a 765 pix width area.
if @greater(%%imgwidth,%%imgheight)
if @greater(%%imgwidth,766)
rem info %%aspectratio %%imgwidth %%imgheight
%%downscaleheight = @FDIV(765,%%aspectratio)
%%printwidth = 765
%%printheight = %%downscaleheight
else
%%upscalehight = @FDIV(765,%%aspectratio)
%%printwidth = 765
%%printheight = %%upscalehight
end
end
rem if image is square fits square 765 pix area.
if @equal(%%imgheight,%%imgwidth)
%%printwidth = 765
%%printheight = 765
end
|
|
|
| Back to top |
|
 |
Boo Valued Contributor


Joined: 31 Oct 2003 Posts: 599 Location: Gulf Breeze, Florida USA
|
|
| Back to top |
|
 |
Vic D'Elfant Past Contributor


Joined: 26 Jun 2002 Posts: 673 Location: The Netherlands
|
Posted: Sat Oct 23, 2004 6:07 pm Post subject: |
|
|
I wrote a similar program a few months ago... Perhaps this code is usefull to you...
| Code: |
list create, 1
list add, 1, C:\blah\blub.jpg
# etc... all items should be full paths to the file
# Maximum height
%%Height = 100
# Maximum width
%%Width = 100
# Output directory
%%OutputFolder = @path(%0)scaled
if @greater(@convert(imgheight, @item(1)), %%Height) @greater(@convert(imgwidth, @item(1)), %%Width)
if @greater(@convert(imgheight, @item(1)), @convert(imgwidth, @item(1)))
%%Factor = @fdiv(@convert(imgwidth, @item(1)), @convert(imgheight, @item(1)))
convert scale, @item(1), %%OutputFolder\@name(@item(1)).@ext(@item(1)), @format(@fmul(%%Height, %%Factor), .0), %%Height
else
%%Factor = @fdiv(@convert(imgheight, @item(1)), @convert(imgwidth, @item(1)))
convert scale, @item(1), %%OutputFolder\@name(@item(1)).@ext(@item(1)), %%Width, @format(@fmul(%%Width, %%Factor), .0)
end
end |
Vic _________________ phpBB Development Team |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|