Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9266711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:22:55+00:00 2026-06-18T14:22:55+00:00

Trying to create a group object with an image and a text object. It’s

  • 0

Trying to create a group object with an image and a text object. It’s sort of like an icon followed by text. Having trouble aligning the objects properly. I can manually set the left,top and adjust them, but the text, font etc.. may change at run time.

When the font/text length changes the alignment gets messed up again. Is there any way to ensure the text always starts after the image (regardless of the text length, font etc..)

If there is no way built in fabric to do this, is there any workaround to solve the problem? Here’s the code I tried and jsFiddle link below, you can see how the image and text is overlapped. Thanks.

var canvas = new fabric.Canvas('canvas');
fabric.Image.fromURL('http://i.imgur.com/vews5Vd.jpg', function(img) {
    var img1 = img.scale(1).set({ left: 0, top: 0 });
    var text = new fabric.Text('the_text_sample', {
                fontFamily: 'Arial',
                fontSize:30,
                left:img1.width,
                top:10,

            });
    var group = new fabric.Group([ img1,text ], { left: 200, top: 200 });
    canvas.add(group);
});

http://jsfiddle.net/gCpnz/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T14:22:56+00:00Added an answer on June 18, 2026 at 2:22 pm

    You’re close…just be sure to set the text.top property to equal half-image-height + half-text-height. Ditto with text.left.

    After the text object is created, the text width/height can be gotten using text.getBoundingRectWidth() and text.getBoundingRectHeight().

    So your code becomes:

    var scaleFactor=1.0
    var canvas = new fabric.Canvas('canvas');
    fabric.Image.fromURL('http://i.imgur.com/vews5Vd.jpg', function(img) {
        var img1 = img.scale(scaleFactor).set({ left: 0, top: 0 });
        var text = new fabric.Text('the_text_sample', {
                    fontFamily: 'Arial',
                    fontSize:30,
                });
                text.set("top",img.height*scaleFactor/2+text.getBoundingRectHeight()/2);
                text.set("left",-img.width*scaleFactor/2+text.getBoundingRectWidth()/2);  
    
        var group = new fabric.Group([ img1,text ], { left: 200, top: 200 });
        canvas.add(group);
    });
    

    Here is a Fiddle:

    http://jsfiddle.net/m1erickson/5Wzvg/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a table-like object within an SVG document. Currently, due to
I am trying to create a group of dropdowns using knockout out that allow
I'm trying to create a checkbox group where the option names can be clicked
I'm trying to create a data extractor algoritm from group buying sites to build
I am trying to create a report that has a summary for each group.
I am trying to create a conversations based messaging system. I want to group
Background / Goal More or less, I'm trying to create a nested group of
I'm trying to create a Messages object that inherits Array. The messages will gather
I'm trying to create a POCO object called Friend.cs. I can't seem to create
I am trying to create a script to batch mark a group of users

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.