Code Monkey home page Code Monkey logo

Comments (5)

tanaikech avatar tanaikech commented on August 31, 2024

Thank you for your comment. In your comment, you want to modify the height but you don't want to modify the width. Is my understanding correct?

from imgapp.

wesselvannierop avatar wesselvannierop commented on August 31, 2024

Thanks for your quick reply. Excuse me if I was unclear. With your function, doResize, I can input the width for an image to scale it, but keep the same aspect ratio. However, I found out that for vertical images, width (in your function) means the 'longest' side, so the vertical side. This was a bit confusing. But the real problem for me is that I have an maximum length for the horizontal side (of an vertical image). Which with your function would be height. So when I set the width of a 4:3 vertical image it's height will be longer then if I set an 16:9 vertical image with the same width. Therefore I'd like to set It's height to a specific value and scale it accordingly. This way the image fits my boundaries. I'm not very experienced with google script so I can't figure this out myself. Hopefully you'll be able to help. If you still have doubts about my question, I could make some screenshots of my problem with annotations.

from imgapp.

tanaikech avatar tanaikech commented on August 31, 2024

Thank you for replying. I'm really sorry for my poor English skill. I couldn't understand about "vertical images". And unfortunately, I cannot see the vision of your issue. But I can show you the method of resize of this library. You can see the detail information at here. If this is not useful for your situation, I'm sorry.

from imgapp.

wesselvannierop avatar wesselvannierop commented on August 31, 2024

I figured it out with basic google script functions, if other people find this, this may be of use:

//[...]
//create image with width of 500 and correct aspect ratio
//if it is vertical image this also works (width is always the width)
var newWidth = 500;
//oImg contains the appended image
oImg = oImg.getParent().asParagraph().appendInlineImage(blob);
// Calculate (aspect) ratio
var orgWidth = oImg.getWidth();
var orgHeight = oImg.getHeight();
var ratio = orgHeight/orgWidth;
//Calculate new height for width of 500 and same ratio
var newHeight = newWidth*ratio;
//Set new height and width to image
oImg.setWidth(newWidth).setHeight(newHeight);

from imgapp.

tanaikech avatar tanaikech commented on August 31, 2024

I'm glad your issue was solved.

from imgapp.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.