• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Issue with uploaded images.

Guest
Feb 19, 2013 Feb 19, 2013

Copy link to clipboard

Copied

Having an issue with pictures that is uploaded to the site. On a page I have a div tag set to a certain size, but if someone uploads an image that is bigger than the size of the div it ignores the div size. The size of the div is 500px by 500px. I even tried a table with a set dimension and still no go. I did think of using the cfimage resize function, but thought to myself that if someone uploads an image that isn't bigger then500px X 500px it will extend the size i set and might blur the image, so i guess that's a no go.

Is there a way to force the image to not extend past the size I set in the div?

Views

774

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Contributor , Feb 20, 2013 Feb 20, 2013

Ok, let's say the user uploads the image to /home/user/www/uploads, and the filename is avatar.jpg

You can do this:

<cfset uploadfile = "/home/user/www/uploads/avatar.jpg">

<cfimage source="#uploadfile#" name="userimage">

<cfif userimage.width gt 500>

<cfimage

    action="resize"

    width="500"

    height=""

    source="#uploadfile#"

    destination="/home/user/www/avatars/avatar.jpg"

    overwrite="true">

<cfelse>

<cffile

    action="move"

    source="#uploadfile#"

    destination="/home/user/www/avatars/avat

...

Votes

Translate

Translate
Contributor ,
Feb 19, 2013 Feb 19, 2013

Copy link to clipboard

Copied

You can check the image dimensions using <cfimage>

<cfimage source="#image_file#" name="thisimage">

thisimage.height is the height

thisimage.width is the width

Once you check the height/width, you can resize if the image is too large, or leave it alone if it's not.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 19, 2013 Feb 19, 2013

Copy link to clipboard

Copied

Sorry i'm really new to cf and don't quite understand the "thisimage.height and thisimage.width". i looked at the livedocs online and it didn't have an example for it. Could you please explain?

Thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 20, 2013 Feb 20, 2013

Copy link to clipboard

Copied

Ok, let's say the user uploads the image to /home/user/www/uploads, and the filename is avatar.jpg

You can do this:

<cfset uploadfile = "/home/user/www/uploads/avatar.jpg">

<cfimage source="#uploadfile#" name="userimage">

<cfif userimage.width gt 500>

<cfimage

    action="resize"

    width="500"

    height=""

    source="#uploadfile#"

    destination="/home/user/www/avatars/avatar.jpg"

    overwrite="true">

<cfelse>

<cffile

    action="move"

    source="#uploadfile#"

    destination="/home/user/www/avatars/avatar.jpg">

</cfif>

If the avatar is over 500px wide, it resizes it and puts it in the avatars folder (or wherever you want it to go).  If not, it just moves it.  The "userimage" in userimage.width is just the name="" from the first <cfimage> tag.  It can be whatever you want, as long as it matches that name.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 21, 2013 Feb 21, 2013

Copy link to clipboard

Copied

That did it. Tweaked it abit, but it worked.

Thanks alot.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 21, 2013 Feb 21, 2013

Copy link to clipboard

Copied

LATEST

Glad you got it working!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation