SaiGonSoftware / Awesome-CMS-Core

Awesome CMS Core is an open source CMS built using ASP.Net Core & ReactJS with module seperation concern in mind and provide lastest trend of technology like .Net Core, React, Webpack, SASS, Background Job, Message Queue.
https://awesomecmscore.azurewebsites.net/
Apache License 2.0
417 stars 136 forks source link

Image resize using ImageSharp #349

Closed ngohungphuc closed 5 years ago

ngohungphuc commented 5 years ago

https://github.com/SaiGonSoftware/Awesome-CMS-Core/issues/321 https://github.com/SaiGonSoftware/Awesome-CMS-Core/issues/326 https://github.com/SaiGonSoftware/Awesome-CMS-Core/issues/337

ngohungphuc commented 5 years ago
public void RunImageProcessQueue()
        {
            var factory = new ConnectionFactory() { HostName = "localhost" };
            using (var connection = factory.CreateConnection())
            using (var channel = connection.CreateModel())
            {
                channel.QueueDeclare(queue: QueueName.ImageResizeProcessing.ToString(),
                    durable: true,
                    exclusive: false,
                    autoDelete: false,
                    arguments: null);

                //Fair dispatch setup
                channel.BasicQos(prefetchSize: 0, prefetchCount: 1, global: false);
                Console.WriteLine(" [*] Waiting for messages.");

                var consumer = new EventingBasicConsumer(channel);
                consumer.Received += (model, ea) =>
                {
                    var body = ea.Body;
                    var assetMessage = Encoding.UTF8.GetString(body);
                    Console.WriteLine(" [x] Received {0}", assetMessage);

                    var imageName = assetMessage.Split("\\")[1];
                    var s =  ProjectPath.ToApplicationPath(imageName);
                    var assetPath = $"{ProjectPath.GetApplicationRoot()}\\wwwroot\\{assetMessage}";
                    var path = "D:\\SourceCode\\Awesome-CMS-Core\\src\\AwesomeCMSCore\\AwesomeCMSCore";
                    using (var image = Image.Load(path))
                    {
                        image.Mutate(x => x
                             .Resize(295, 205)
                             .Grayscale());
                        image.Save(imageName);
                    }

                    channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);
                };

                channel.BasicConsume(queue: QueueName.ImageResizeProcessing.ToString(),
                    autoAck: false,
                    consumer: consumer);

                Console.WriteLine(" Press [enter] to exit.");
                Console.ReadLine();
            }

Still can't resize eventhough I can load it cc @AbelianKraun

AbelianKraun commented 5 years ago

I will check this ASAP when I have time, I'm still configuring the environment.