Giter Club home page Giter Club logo

psd2css's Introduction

psd2css

A forked Photoshop script that exports all visible layers to CSS with the top, left, width, height, and background image properties using rems.

This is a script that I created for myself that looks for all visible layers/groups and only exports the items at the root level. The top/left properties allow me to absolutely positiong the elements.

There currently is no support for child groups or selected layers, nor was this ever intended for scalablity. This supports my current workflow.

Instructions

  1. Place the "Export Elements to CSS.jsx" file into your Photoshop Scripts folder: ~/Applications/Adobe\ Photoshop\ CC/Presets/Scripts

  2. Restart Photoshop

  3. Naigate to File > Scripts and run Export Elements to CSS

  4. You can add this to your shortcuts via Edit > Keyboard Shortcuts

Export Example

#logo{
 top: 10rem;
 left: 11.8rem;
 width: 8.4rem;
 height: 5.5rem;
 background-image: url('#{url}images/[email protected]');
}

REM units

I mostly work with retina assets so all of my Photoshop documents are at retina size. This script collects all of the layer measurements and divides them in half to get our base measurement. Then I round to the nearest 10th so that we have a 1:1 px ratio. For example: 11.8rem = 118px. This allows me to properly resize elements with full-width background images.

Background Images

The background-image property references a SASS variable: $url which allows me to define the image URL path: $url: 'image/path/to/files' and then I append it with the retina prefix @2x:

background-image: url('#{$url}images/"+layer.name+"@2x.png');

I am then able to declare all child elements to fill the background-image to the size of the parent element:

#container * { -webkit-background-size: 100% auto }

psd2css's People

Contributors

miguelsolorio avatar

Stargazers

 avatar Jeongrok Oh avatar

Watchers

James Cloos avatar Miguel avatar

Forkers

lyhiving

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.