ImageMagick crop keeping the height



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I'm trying to crop image by height with this command line:



convert 1053257.png -gravity South -crop 2910x3312+0+0 -background black +repage image-cropped-top.png


The generated image is not cropped correctly, as the dimensions after running the command are 2791 x 3312.
The width is cropped as well!



Can anyone help with this?










share|improve this question






























    1















    I'm trying to crop image by height with this command line:



    convert 1053257.png -gravity South -crop 2910x3312+0+0 -background black +repage image-cropped-top.png


    The generated image is not cropped correctly, as the dimensions after running the command are 2791 x 3312.
    The width is cropped as well!



    Can anyone help with this?










    share|improve this question


























      1












      1








      1








      I'm trying to crop image by height with this command line:



      convert 1053257.png -gravity South -crop 2910x3312+0+0 -background black +repage image-cropped-top.png


      The generated image is not cropped correctly, as the dimensions after running the command are 2791 x 3312.
      The width is cropped as well!



      Can anyone help with this?










      share|improve this question
















      I'm trying to crop image by height with this command line:



      convert 1053257.png -gravity South -crop 2910x3312+0+0 -background black +repage image-cropped-top.png


      The generated image is not cropped correctly, as the dimensions after running the command are 2791 x 3312.
      The width is cropped as well!



      Can anyone help with this?







      imagemagick






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 16 '18 at 13:40









      dferenc

      4,851122333




      4,851122333










      asked Nov 16 '18 at 12:09









      HamidIngHamidIng

      437




      437






















          2 Answers
          2






          active

          oldest

          votes


















          2














          The general form is:



          convert input.jpg -crop WIDTHxHEIGHT+0+0 result.jpg



          If you want to crop to a specific width, say 1024, leaving the height unaffected:



          convert image.jpg -crop 1024x+0+0 result.jpg



          If you want to crop to a specific height, say 768, leaving the width unaffected - note the height is after the x:



          convert image.jpg -crop x768+0+0 result.jpg



          If you want to crop to a maximum width and height, say 1024 wide by 768 tall without distorting the aspect ratio:



          convert image.jpg -crop 1024x768+0+0 result.jpg



          If you want to crop to a specific width and height, say 1024 wide by 768 tall and are happy to allow gross distortions:



          convert image.jpg -crop 1024x768+0+0! result.jpg


          Think of the exclamation mark as meaning "just do it!". Note that the backslash is only needed on Linux/Unix/macOS to escape the exclamation mark, you omit the backslash on Windows.




          Note, if you are saving the cropped image in PNG format, you probably want to reset the page afterwards so the image "forgets" it used to be part of a larger image:



          convert input.jpg -crop 1024x768+0+0 +repage result.png





          share|improve this answer

























          • thanks a lot this was exactly what I needed

            – HamidIng
            Nov 19 '18 at 8:52


















          2














          With ImageMagick a problem like that can occur if you've done a "-trim" to the image before the crop. When you "-trim" an image it can still remember the original page dimensions from before the trim, then when you crop it, it uses those page dimensions as the starting reference for the crop. You probably need to "+repage" before the crop to start with fresh paging information. Try something like this...



          convert 1053257.png -gravity South +repage -crop 2910x3312+0+0 +repage image-cropped-top.png





          share|improve this answer

























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53337631%2fimagemagick-crop-keeping-the-height%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2














            The general form is:



            convert input.jpg -crop WIDTHxHEIGHT+0+0 result.jpg



            If you want to crop to a specific width, say 1024, leaving the height unaffected:



            convert image.jpg -crop 1024x+0+0 result.jpg



            If you want to crop to a specific height, say 768, leaving the width unaffected - note the height is after the x:



            convert image.jpg -crop x768+0+0 result.jpg



            If you want to crop to a maximum width and height, say 1024 wide by 768 tall without distorting the aspect ratio:



            convert image.jpg -crop 1024x768+0+0 result.jpg



            If you want to crop to a specific width and height, say 1024 wide by 768 tall and are happy to allow gross distortions:



            convert image.jpg -crop 1024x768+0+0! result.jpg


            Think of the exclamation mark as meaning "just do it!". Note that the backslash is only needed on Linux/Unix/macOS to escape the exclamation mark, you omit the backslash on Windows.




            Note, if you are saving the cropped image in PNG format, you probably want to reset the page afterwards so the image "forgets" it used to be part of a larger image:



            convert input.jpg -crop 1024x768+0+0 +repage result.png





            share|improve this answer

























            • thanks a lot this was exactly what I needed

              – HamidIng
              Nov 19 '18 at 8:52















            2














            The general form is:



            convert input.jpg -crop WIDTHxHEIGHT+0+0 result.jpg



            If you want to crop to a specific width, say 1024, leaving the height unaffected:



            convert image.jpg -crop 1024x+0+0 result.jpg



            If you want to crop to a specific height, say 768, leaving the width unaffected - note the height is after the x:



            convert image.jpg -crop x768+0+0 result.jpg



            If you want to crop to a maximum width and height, say 1024 wide by 768 tall without distorting the aspect ratio:



            convert image.jpg -crop 1024x768+0+0 result.jpg



            If you want to crop to a specific width and height, say 1024 wide by 768 tall and are happy to allow gross distortions:



            convert image.jpg -crop 1024x768+0+0! result.jpg


            Think of the exclamation mark as meaning "just do it!". Note that the backslash is only needed on Linux/Unix/macOS to escape the exclamation mark, you omit the backslash on Windows.




            Note, if you are saving the cropped image in PNG format, you probably want to reset the page afterwards so the image "forgets" it used to be part of a larger image:



            convert input.jpg -crop 1024x768+0+0 +repage result.png





            share|improve this answer

























            • thanks a lot this was exactly what I needed

              – HamidIng
              Nov 19 '18 at 8:52













            2












            2








            2







            The general form is:



            convert input.jpg -crop WIDTHxHEIGHT+0+0 result.jpg



            If you want to crop to a specific width, say 1024, leaving the height unaffected:



            convert image.jpg -crop 1024x+0+0 result.jpg



            If you want to crop to a specific height, say 768, leaving the width unaffected - note the height is after the x:



            convert image.jpg -crop x768+0+0 result.jpg



            If you want to crop to a maximum width and height, say 1024 wide by 768 tall without distorting the aspect ratio:



            convert image.jpg -crop 1024x768+0+0 result.jpg



            If you want to crop to a specific width and height, say 1024 wide by 768 tall and are happy to allow gross distortions:



            convert image.jpg -crop 1024x768+0+0! result.jpg


            Think of the exclamation mark as meaning "just do it!". Note that the backslash is only needed on Linux/Unix/macOS to escape the exclamation mark, you omit the backslash on Windows.




            Note, if you are saving the cropped image in PNG format, you probably want to reset the page afterwards so the image "forgets" it used to be part of a larger image:



            convert input.jpg -crop 1024x768+0+0 +repage result.png





            share|improve this answer















            The general form is:



            convert input.jpg -crop WIDTHxHEIGHT+0+0 result.jpg



            If you want to crop to a specific width, say 1024, leaving the height unaffected:



            convert image.jpg -crop 1024x+0+0 result.jpg



            If you want to crop to a specific height, say 768, leaving the width unaffected - note the height is after the x:



            convert image.jpg -crop x768+0+0 result.jpg



            If you want to crop to a maximum width and height, say 1024 wide by 768 tall without distorting the aspect ratio:



            convert image.jpg -crop 1024x768+0+0 result.jpg



            If you want to crop to a specific width and height, say 1024 wide by 768 tall and are happy to allow gross distortions:



            convert image.jpg -crop 1024x768+0+0! result.jpg


            Think of the exclamation mark as meaning "just do it!". Note that the backslash is only needed on Linux/Unix/macOS to escape the exclamation mark, you omit the backslash on Windows.




            Note, if you are saving the cropped image in PNG format, you probably want to reset the page afterwards so the image "forgets" it used to be part of a larger image:



            convert input.jpg -crop 1024x768+0+0 +repage result.png






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 16 '18 at 14:01

























            answered Nov 16 '18 at 13:50









            Mark SetchellMark Setchell

            93.2k784189




            93.2k784189












            • thanks a lot this was exactly what I needed

              – HamidIng
              Nov 19 '18 at 8:52

















            • thanks a lot this was exactly what I needed

              – HamidIng
              Nov 19 '18 at 8:52
















            thanks a lot this was exactly what I needed

            – HamidIng
            Nov 19 '18 at 8:52





            thanks a lot this was exactly what I needed

            – HamidIng
            Nov 19 '18 at 8:52













            2














            With ImageMagick a problem like that can occur if you've done a "-trim" to the image before the crop. When you "-trim" an image it can still remember the original page dimensions from before the trim, then when you crop it, it uses those page dimensions as the starting reference for the crop. You probably need to "+repage" before the crop to start with fresh paging information. Try something like this...



            convert 1053257.png -gravity South +repage -crop 2910x3312+0+0 +repage image-cropped-top.png





            share|improve this answer





























              2














              With ImageMagick a problem like that can occur if you've done a "-trim" to the image before the crop. When you "-trim" an image it can still remember the original page dimensions from before the trim, then when you crop it, it uses those page dimensions as the starting reference for the crop. You probably need to "+repage" before the crop to start with fresh paging information. Try something like this...



              convert 1053257.png -gravity South +repage -crop 2910x3312+0+0 +repage image-cropped-top.png





              share|improve this answer



























                2












                2








                2







                With ImageMagick a problem like that can occur if you've done a "-trim" to the image before the crop. When you "-trim" an image it can still remember the original page dimensions from before the trim, then when you crop it, it uses those page dimensions as the starting reference for the crop. You probably need to "+repage" before the crop to start with fresh paging information. Try something like this...



                convert 1053257.png -gravity South +repage -crop 2910x3312+0+0 +repage image-cropped-top.png





                share|improve this answer















                With ImageMagick a problem like that can occur if you've done a "-trim" to the image before the crop. When you "-trim" an image it can still remember the original page dimensions from before the trim, then when you crop it, it uses those page dimensions as the starting reference for the crop. You probably need to "+repage" before the crop to start with fresh paging information. Try something like this...



                convert 1053257.png -gravity South +repage -crop 2910x3312+0+0 +repage image-cropped-top.png






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 16 '18 at 21:39

























                answered Nov 16 '18 at 15:10









                GeeMackGeeMack

                1,201125




                1,201125



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53337631%2fimagemagick-crop-keeping-the-height%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Top Tejano songwriter Luis Silva dead of heart attack at 64

                    ReactJS Fetched API data displays live - need Data displayed static

                    政党