宜兴通达竭诚为您服务。

通达科技 - 宜兴电脑维护及IT服务外包服务商

Image Generation With Different Sizes
  • 上传者: Administrator
  • 上传时间:2024年02月24日 07时38分29秒
摘要:
Image Generation With Different Sizes** Huge images are impractical for any website. It increases the page size and slows down accordingly. This leads ......
正文 相关文章 请喝咖啡

    Image Generation With Different Sizes

    Huge images are impractical for any website. It increases the page size and slows down accordingly. This leads to terrible SEO rankings and guest unhappiness. This recipe explores how to create images of different sizes. Using the right images can reduce the page size of your website and further improve page stacking time.

    Odoo uses the image.mixin class to generate images of different sizes. To do this, your model should inherit image.mixin. The image.mixin model is an AbstractModel, so its tables are not in the database. I really want to include it in my model to use it.

    This image.mixin allows you to save images with a maximum resolution of 1,920x1,920. If you save an image with a resolution higher than 1920x1920, Odoo will scale it down to 1920x1920. At the same time, Odoo also preserves image resolution and prevents distortion. For example, if you send an image with a resolution of 2400 x 1600, the image_1920 field will have a resolution of 1920 x 1280.

    pre class="wp-block-code">class ProductImage(models.Model): _name = 'product.image' _description = "Product Image" _inherit = ['image.mixin']

    As a result, image.mixin is inherited, so five new binary fields are added to the model to store images of different sizes. Here is a list of fields and their resolutions:

    ● image_1920: 1,920x1,920

    ● image_1024: 1,024x1,024

    ● image_512: 512x1,512

    ● image_256: 256x256

    ● image_128: 128x128

    In the above field only image_1920 is editable. If you change the image_1920 field, the other image fields will be read and updated. Therefore, the backend tree perspective of the model should use the image_1920 field to allow the client to upload an image. Either way, you're stacking a huge image_1920 image in your tree view. Nonetheless, there is a way to evolve the execution using the image_1920 image in a tree view showing more conservative images. For example, you can use the image_1920 field to display the image_128 field. You can check the following code to do this:

    <field name="image_1920" widget="image" class="oe_avatar" options="{'preview_image': 'image_128'}"/ >

    With image.mixin, you can get the image with specific resolutions, yet imagine a scenario where you need to utilize an image with another resolution. To do as such, you can create a parallel field image to your model.

    image_1600 = fields.Image("Image 1600", max_width=1600, max_height=1600)

    This will create a new field image_1600, and when you remove the image, it will resize to 1600 x 1600 resolution. Note that this is not strictly necessary for image.mixin. Since we're just shrinking the image to 1,600 x 1,600, we need to add that box to the tree view. Changing this does not change the following image fields in image.mixin. Add the related="image_1920" attribute to the field definition if you want to relate it to the current image.mixin field.

    本文章从网上收集,如有侵权请联系tderp@tderp.com删除
  • 微信扫一扫,一分也是爱:
  • 微信

服务原则及地区范围

宜兴通达网络科技有限公司,地处中国宜兴环科园内,是一家高新技术企业。公司在企业网络维护和企业信息化建设与咨询方面,有10多年经验。

我公司愿与客户一道,力求彻底解决客户问题!
我们不是在给企业提供“头痛医头、脚痛医脚”的暂时解决方案,而是在部署根本性安全与稳定服务!!
我们愿携手客户,建立企业IT规划;杜绝随意安装系统、软件等操作;力求共同维护有序、安全、稳定的网络办公环境!!!
IT服务,服务是根本,客户是上帝;我们提供快速响应、快速上门、快速排查,提供优质高效的服务!!!!

通达科技提供全国范围内的服务,服务形式包括远程协助、电话咨询、电子邮件咨询、传真咨询、问答平台的问题解决等。

宜兴地区提供上门服务:

  • 市区服务:宜城街道、城北街道(屺亭街道)、新街街道、新庄街道、环科园、渚桥开发区
  • 市郊服务:张渚镇、西渚镇、太华镇、徐舍镇、官林镇、杨巷镇、新建镇、和桥镇、高塍镇、万石镇、周铁镇、芳桥镇、丁蜀镇、湖父镇。
  • 联系电话:189-21-343434
  • 在线沟通: